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