【发布时间】:2021-06-19 06:46:10
【问题描述】:
我尝试了一个 spring boot 2.4.0 应用程序,编写了一些测试。这是我的测试课
@SpringBootTest
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:application-test.properties")
public class SampleTest {
@Test
public void testMethod1() {
//some logic
}
}
我有这个结构
src/
main/
java/
//// further packages
resources/
bootstrap.yml
test/
resources/
application-test.properties
上面的代码选择 bootstrap.yml 因为它包含这个属性 spring.profiles.active=${PROFILE} 顺便说一句,这个应用程序正在使用 spring-cloud-config
它给出了这个错误
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'PROFILE' in value "${PROFILE}"
为什么 spring-boot 没有提取我的测试属性文件?它始终优先于 bootstrap.yml 文件。请帮忙
【问题讨论】:
-
移除 TestPropertySource 和 EnableConfigurationProperties
-
为测试属性尝试相同的名称和扩展名。我的意思是在
src/test/resource中将application-test.properties更改为application.yml -
@SimonMartinelli 试过 EnableConfigurationProperties,没用
标签: spring-boot spring-boot-test