[英]@LocalServerPort missing from Spring Boot 2.0.0.RELEASE
我将我的应用程序从 spring boot 1.5.9.RELEASE 升级到 2.0.0.RELEASE,我无法再导入org.springframework.boot.context.embedded.LocalServerPort
。 我用它来注入服务器在测试期间运行的端口:
public class Task1Test {
@LocalServerPort
private int port;
Spring 发行说明未提及此删除, @LocalServerPort 未被弃用。
我可以使用 Spring Boot 2.0 中的等效项吗?
编辑:我很确定 class 不见了。 我收到这些编译错误:
[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
看起来它被移动到org.springframework.boot.web.server.LocalServerPort,恕不另行通知。 希望有所帮助。
@LocalServerPort 现在在org.springframework.boot.test.web.server.LocalServerPort
在测试代码中更新您的导入。
此处 Spring 启动文档的相关链接https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/web/server/LocalServerPort.html
请注意,如果您使用的是 Spring Boot Getting Started 指南,这些指南仍在使用旧的命名空间,因此您将看到一个没有修复选项的构建错误。 您将需要手动更新它。
根据此API文档,它似乎已被移至spring-boot-starter-web
依赖项。
尝试添加此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.