日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

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

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

鑒于我有以下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;

}

我希望能夠運(yùn)行以下測試:

@RunWith(SpringRunner.class)

@SpringBootTest

public class S2Test {

@Autowired

S2 s;

@Test

public void t2() {

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

}

}

我的問題是,因?yàn)槲蚁雴为?dú)測試S2類,因?yàn)樗褂?#64;Autowired我必須在我的測試中有一個Spring上下文,但是當(dāng)Spring上下文啟動時它會嘗試創(chuàng)建包含bean的所有3個bean與@Value.由于此值僅可從Spring Cloud Config Server獲得,因此無法創(chuàng)建上下文,從而產(chǎn)生錯誤:org.springframework.beans.factory.BeanCreationException:創(chuàng)建名為’serviceConfig’的bean時出錯:注入自動連接的依賴項(xiàng)失敗;嵌套異常是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?

超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。