gpt4 book ai didi

java - 如何在 Spring Boot 测试中覆盖 application-test.yml ?

转载 作者:行者123 更新时间:2023-12-02 20:03:15 28 4
gpt4 key购买 nike

我有 src/main/test/resources/application-test.yml,根据 SpringBootTest 它将加载 application.yml,然后加载 application-test.yml。但我面临一种情况,我只想为一个测试覆盖 application-test.yml 中的某些属性,但其他测试需要使用 application-test.yml 中的属性。我该怎么做?

我尝试使用@TestPropertySource注释来覆盖,但它不起作用。

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes= MyApplicationTestApplication.class)
@ActiveProfiles("test")
@DirtiesContext
@TestPropertySource(locations = {"classpath:application-test.yml",
"classpath:file-test.properties"})

最佳答案

感谢您的评论和回答,只是想添加对我有用的内容

@SpringBootTest(properties = "some.property=localhost:9094") 

Link to doc

关于java - 如何在 Spring Boot 测试中覆盖 application-test.yml ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55367576/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com