通过@ContextConfiguration(initializers=…)支持ApplicationContextInitializer配置(或者,在Spock的更高版本中,通过@SpringApplicationConfiguration(initi
通过@ContextConfiguration(initializers=…)支持ApplicationContextInitializer配置(或者,在Spock的更高版本中,通过@SpringApplicationConfiguration(initi,spring,spring-annotations,spring-test,Spring,Spring Annotations,Spring Test,通过@ContextConfiguration(initializers=…)支持ApplicationContextInitializer配置(或者,在Spock的更高版本中,通过@SpringApplicationConfiguration(initializers=…))。因此,总的来说,它应该是有效的。尝试最新版本,如果这不起作用,请考虑打开一个针对斯波克的bug报告。这是否需要 SpRunJuni4CaseRuns工作?我的测试是在Groovy中进行的(使用Spock和SpringAp
通过
@ContextConfiguration(initializers=…
)支持ApplicationContextInitializer
配置(或者,在Spock的更高版本中,通过@SpringApplicationConfiguration(initializers=…)
)。因此,总的来说,它应该是有效的。尝试最新版本,如果这不起作用,请考虑打开一个针对斯波克的bug报告。这是否需要<代码> SpRunJuni4CaseRuns工作?我的测试是在Groovy中进行的(使用Spock和SpringApplicationContextLoader
),并引用Java中的配置类。正在注入my config类中公开的bean,但未调用重写的initialize
方法。Paul,Spring Boot的SpringApplicationContextLoader
支持ApplicationContextInitializer
通过@ContextConfiguration进行配置(初始值设定项=…
)(或者,AfAIK,通过代码< > SpringApplicationConfiguration(初始化器=…)<代码>斯波克后面的版本)。所以一般来说,它应该工作。尝试最新的版本,如果这不起作用,考虑打开一个针对斯波克的bug报告。
@Value("${my.property}")
private String myField;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class)
public class AcceptanceTest implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Configuration
@ComponentScan(basePackages = {
"my.package.one",
"my.package.two"
})
static class ContextConfiguration {
@Bean
public MyBean getMyBean(){
return new MyBean();
}
}
@Autowired
private AnotherBean anotherBean;
@Test
public void testTest(){
assertNotNull(anotherBean);
. . .
}
. . .
@Configuration
public class PropertiesConfig {
@Bean
public PropertyPlaceholderConfigurer myConfigurer() {
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
Properties props = new Properties();
Map myMap = new HashMap<String, String>();
myMap.put("my.property", "my value");
myMap.put("second.my.property", "another value");
props.putAll(myMap);
configurer.setProperties(props);
return configurer;
}
}
@SpringBootTest
@TestPropertySource(properties = [ "my.test.property = bar", "..." ])