Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有@RunWith(SpringJUnit4ClassRunner.class)的概要文件_Java_Spring_Spring Junit_Springjunit4classrunner - Fatal编程技术网

Java 带有@RunWith(SpringJUnit4ClassRunner.class)的概要文件

Java 带有@RunWith(SpringJUnit4ClassRunner.class)的概要文件,java,spring,spring-junit,springjunit4classrunner,Java,Spring,Spring Junit,Springjunit4classrunner,我的TestSuite有两种配置,它们为注入提供了不同的bean。只要我用注释设置我的配置文件,这就行了 @ActiveProfiles(profiles={“a”})和@ActiveProfiles(profiles={“b”}) 但我似乎无法从属性源文件设置它 我的注释看起来像 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AConfig.class, BConfig.class }) @Pr

我的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)

只要我用注释设置我的配置文件,这就行了

这是意料之中的事。

ActiveProfiles
不依赖于
spring.profiles.active
属性

ActiveProfiles是用于声明 加载时应使用哪些活动bean定义配置文件 测试类的ApplicationContext

而作为
属性别名的
配置文件
属性需要与配置文件一起赋值,以激活测试

要激活的bean定义配置文件

它不使用
spring.profiles.active
属性


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

尝试使用EL查看您是否可以实际访问测试中的任何属性?这将确定是否正在加载属性文件谢谢回答。我的意图是在
application.properties
文件中提供默认配置文件,然后在CI下运行时,使用env覆盖配置文件。我怎样才能达到同样的结果?