19

I upgraded my app from spring boot 1.5.9.RELEASE to 2.0.0.RELEASE, and I can no longer import org.springframework.boot.context.embedded.LocalServerPort. I was using this to inject the port the server is running on during a test:

public class Task1Test {

    @LocalServerPort
    private int port;

The Spring release notes do not mention this removal and @LocalServerPort was not deprecated.

Is there an equivalent in Spring Boot 2.0 that I can use?

Edit: I'm pretty sure that the class is gone. I'm getting these compilation errors:

[ERROR] ... Task1Test.java:[12,49]package org.springframework.boot.context.embedded does not exist
[ERROR] ... Task1Test.java:[46,6] cannot find symbol
  symbol:   class LocalServerPort
Kevin
  • 1,080
  • 3
  • 15
  • 41

3 Answers3

29

It looks like it was moved to org.springframework.boot.web.server.LocalServerPort without notice. Hope that helps.

hd1
  • 33,938
  • 5
  • 80
  • 91
5

@LocalServerPort is now in org.springframework.boot.test.web.server.LocalServerPort

Update your imports in the test code.

Relevant link to the Spring boot docs here https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/web/server/LocalServerPort.html

the change is notified here https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/server/LocalServerPort.html

Note that if you are using the Spring Boot Getting Started guides, the guides are still using the old namespace and hence you will see a build error without an option to fix. You will need to update this manually.

Marsan
  • 51
  • 1
  • 3
2

It seems it's been moved to spring-boot-starter-web dependency as per this API documentation.

Try adding this maven dependency to see if that fixes it

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>
Pankaj Gadge
  • 2,748
  • 3
  • 18
  • 25