日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java测试spring cloud_java – 从Spring引导单元测试中排除Spring Cloud Config Server

發布時間:2024/2/28 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java测试spring cloud_java – 从Spring引导单元测试中排除Spring Cloud Config Server 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鑒于我有以下3豆:

@Component

public class ServiceConfig {

// This value is only available from the Spring Cloud Config Server

@Value("${example.property}")

private String exampleProperty;

public String getExampleProperty() {

return exampleProperty;

}

}

@Component

public class S1 {

int i = 1;

}

@Component

public class S2 {

@Autowired

S1 s1;

}

我希望能夠運行以下測試:

@RunWith(SpringRunner.class)

@SpringBootTest

public class S2Test {

@Autowired

S2 s;

@Test

public void t2() {

System.out.println(s.s1.i);

}

}

我的問題是,因為我想單獨測試S2類,因為它使用@Autowired我必須在我的測試中有一個Spring上下文,但是當Spring上下文啟動時它會嘗試創建包含bean的所有3個bean與@Value.由于此值僅可從Spring Cloud Config Server獲得,因此無法創建上下文,從而產生錯誤:org.springframework.beans.factory.BeanCreationException:創建名為’serviceConfig’的bean時出錯:注入自動連接的依賴項失敗;嵌套異常是java.lang.IllegalArgumentException:無法在字符串值“${example.property}”中解析占位符’example.property’.

My Question is: How are properties read from Spring Cloud Config

Server handled in the application when unit tests are run, observe in

my test i dont even care about the config so I dont want to explicitly

have to set a value in my test just for the context to be started?

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的java测试spring cloud_java – 从Spring引导单元测试中排除Spring Cloud Config Server的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。