【发布时间】:2018-01-23 15:38:12
【问题描述】:
我的 TestSuite 有两种配置,它们提供了不同的注入 bean。只要我使用注释设置我的个人资料,这就会起作用。
@ActiveProfiles( profiles={"a"}) 和 @ActiveProfiles( profiles={"b"})
但我似乎无法从属性源文件中设置它
我的注释看起来像
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AConfig.class, BConfig.class })
@PropertySource("classpath:/application.properties")
@TestPropertySource(locations = {"classpath:/application.properties"})
public abstract class AbstractTestIT {
...
}
而application.properties的内容是
spring.profiles.active="a"
结果导致依赖不满足
如上所述,@ActiveProfiles 的设置有效,并且使用了正确的 be。
就好像 PropertySource 和/或 TestPropertySource 不适用于 @RunWith(SpringJUnit4ClassRunner.class)
【问题讨论】:
-
尝试使用 EL 来查看您是否可以实际访问测试中的任何属性?这将确定是否正在加载属性文件
标签: java spring spring-junit springjunit4classrunner