【发布时间】:2020-06-16 21:04:37
【问题描述】:
我有一个带有如下自定义配置设置的 Spring Boot 应用程序:
src/main/resources
├── application.properties
├── config1
│ ├── application-dev.properties
│ ├── application-prod.properties
│ └── application.properties
├── config2
│ ├── application-dev.properties
│ ├── application-prod.properties
│ └── application.properties
└── config3
├── application-dev.properties
├── application-prod.properties
└── application.properties
在运行时使用的配置指定为:
java -jar \
-Dspring.profiles.active=dev \
-Dspring.config.name=application,config1/application \
target/my-application.0.0.1.jar
如何为@SpringBootTest 指定这个?我尝试使用@TestPropertySources,但它不起作用:
@SpringBootTest
@ActiveProfiles("prod")
@TestPropertySources({
@TestPropertySource("classpath:application.properties"),
@TestPropertySource("classpath:application-${spring.profile.active}.properties"),
@TestPropertySource("classpath:config1/application.properties"),
@TestPropertySource("classpath:config1/application-${spring.profile.active}.properties"),
@TestPropertySource("classpath:config2/application.properties"),
@TestPropertySource("classpath:config2/application-${spring.profile.active}.properties"),
@TestPropertySource("classpath:config3/application.properties"),
@TestPropertySource("classpath:config3/application-${spring.profile.active}.properties")
})
【问题讨论】:
标签: spring-boot configuration spring-boot-test