Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@LocalServerPort missing from Spring Boot 2.0.0.RELEASE

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
like image 598
Kevin Avatar asked Mar 16 '18 23:03

Kevin


2 Answers

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>
like image 35
Pankaj Gadge Avatar answered Sep 28 '22 20:09

Pankaj Gadge


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

like image 138
hd1 Avatar answered Sep 28 '22 22:09

hd1