[英]@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
.我将我的应用程序从 spring boot 1.5.9.RELEASE 升级到 2.0.0.RELEASE,我无法再导入
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 . Spring 发行说明未提及此删除, @LocalServerPort 未被弃用。
Is there an equivalent in Spring Boot 2.0 that I can use?我可以使用 Spring Boot 2.0 中的等效项吗?
Edit : I'm pretty sure that the class is gone.编辑:我很确定 class 不见了。 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
It looks like it was moved to org.springframework.boot.web.server.LocalServerPort without notice. 看起来它被移动到org.springframework.boot.web.server.LocalServerPort,恕不另行通知。 Hope that helps.
希望有所帮助。
@LocalServerPort is now in org.springframework.boot.test.web.server.LocalServerPort @LocalServerPort 现在在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此处 Spring 启动文档的相关链接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此处通知更改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.请注意,如果您使用的是 Spring Boot Getting Started 指南,这些指南仍在使用旧的命名空间,因此您将看到一个没有修复选项的构建错误。 You will need to update this manually.
您将需要手动更新它。
It seems it's been moved to spring-boot-starter-web
dependency as per this API documentation. 根据此API文档,它似乎已被移至
spring-boot-starter-web
依赖项。
Try adding this maven dependency to see if that fixes it 尝试添加此maven依赖项以查看是否可以修复它
<!-- 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.