0

我的 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一样,并且使用了正确的被使用。

几乎就好像 PropertySource 和/或 TestPropertySource 不适用@RunWith(SpringJUnit4ClassRunner.class)

4

1 回答 1

1

只要我使用注释设置我的个人资料,这就会起作用。

这是预期的。

ActiveProfiles不依赖spring.profiles.active财产。

ActiveProfiles 是一个类级别的注释,用于声明在为测试类加载 ApplicationContext 时应该使用哪些活动 bean 定义配置文件。

并且作为profiles属性别名的value属性需要与配置文件一起评估以激活测试

要激活的 bean 定义配置文件。

它不使用该spring.profiles.active属性。

spring.profiles.active属性指定哪些配置文件在应用程序的整体配置中处于活动状态,而不是针对单元测试上下文。

于 2017-08-15T16:55:13.073 回答