Spring Boot 2.0.0.RELEASE中缺少@LocalServerPort

Kev*_*vin 8 java spring spring-boot

我将我的应用程序从spring boot 1.5.9.RELEASE升级到2.0.0.RELEASE,我无法再导入org.springframework.boot.context.embedded.LocalServerPort.我正在使用它来注入服务器在测试期间运行的端口:

public class Task1Test {

    @LocalServerPort
    private int port;
Run Code Online (Sandbox Code Playgroud)

春天发行说明没有提到这一点拆卸和@LocalServerPort并没有过时.

我可以使用Spring Boot 2.0中的等效项吗?

编辑:我很确定课程已经消失了.我收到这些编译错误:

[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
Run Code Online (Sandbox Code Playgroud)

hd1*_*hd1 15

看起来它被移动到org.springframework.boot.web.server.LocalServerPort,恕不另行通知.希望有所帮助.


小智 6

@LocalServerPort 现在位于 org.springframework.boot.test.web.server.LocalServerPort中

更新测试代码中的导入。

Spring boot 文档的相关链接位于 https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/web/server/LocalServerPort.html

此处通知更改 https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/server/LocalServerPort.html

请注意,如果您使用 Spring Boot 入门指南,这些指南仍然使用旧的命名空间,因此您将看到构建错误,而没有修复选项。您需要手动更新它。