简体   繁体   English

Spring Boot 2.0.0.RELEASE 中缺少@LocalServerPort

[英]@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.

相关问题 Spring Boot应用程序启动失败并显示2.0.0.RELEASE - Spring Boot application start failed with 2.0.0.RELEASE Spring 2.0.0.RELEASE 中的 Mockito 错误 - Mockito Bug in Spring 2.0.0.RELEASE Spring 启动外部属性不适用于启动 2.0.0.RELEASE,其中包含 spring 批次 - Spring boot external properties not working for boot 2.0.0.RELEASE with spring batch inside 在Spring Boot 2.0.0.RELEASE迁移之后,“获得了不同大小的元组和别名”异常 - “Got different size of tuples and aliases” exception after Spring Boot 2.0.0.RELEASE migration Spring Boot 2.0.0.RELEASE java.lang.ClassNotFoundException:org.springframework.aop.framework.AopProxyUtils - Spring boot 2.0.0.RELEASE java.lang.ClassNotFoundException: org.springframework.aop.framework.AopProxyUtils spring-boot-maven-plugin:2.0.0.RELEASE:repackage 失败:无法重命名 - spring-boot-maven-plugin:2.0.0.RELEASE:repackage failed: Unable to rename SpringBoot 2.0.0.RELEASE中的org.springframework.boot.autoconfigure.web.ErrorAttributes - org.springframework.boot.autoconfigure.web.ErrorAttributes in SpringBoot 2.0.0.RELEASE Spring Data Rest 2.0.0.RELEASE以前使用RC1打破代码工作 - Spring Data Rest 2.0.0.RELEASE Breaks Code Working Previously With RC1 spring-boot-2.0.0.RELEASE中缺少特定的SpringApplication.run重载 - specific overload of SpringApplication.run is missing in spring-boot-2.0.0.RELEASE 从 Spring Boot 1.5.4 升级到 2.0.0 的问题 - Issue upgrading from Spring Boot 1.5.4 to 2.0.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM