如何解决在Spring Boot应用程序的集成测试中使用外部文件覆盖application.yml中的属性
在application.yml
中,我列出了用于缓存的自定义配置。
caches:
- name: cache1
ttl: 30
- name: cache2
ttl: 60
我有一个集成测试,我想从外部文件中覆盖在application.yaml
中指定的值。
我有几个用于不同测试的外部缓存配置文件,test-caches-1.yml
,test-caches-2.yml
等。文件的内容看起来很简单
caches:
- name: test-cache1
ttl: 30
- name: test-cache2
ttl: 60
这是我的考试
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@ContextConfiguration(classes = MyApplication.class)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@TestPropertySource(
properties = { "features.distributed-cache = true" },locations = {"classpath:/caches-configuratilon/test-caches.yml"})
public class CachingConfigurationTest {
@Autowired
CachesConfigurationProperties cachesConfigurationProperties;
@Test
public void myTest() {
// ...
}
}
如果在测试执行过程中删除了locations = {"classpath:/caches-configuratilon/test-caches.yml"}
属性,我会看到application.yml
中的所有缓存。如果将test-caches.yml
的内容放到application-test.yml
,我会看到在那里配置了缓存。
但是,当我将这些缓存放入test-caches.yml
时,什么也没有。有什么想法可以用外部文件application.yml
中的值覆盖test-caches.yml
中的值吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。