问题描述
我正在为一个Spring Batch
项目编写集成测试,该项目具有以下配置
@Configuration
@EnableScheduling
@PropertySource("application.properties")
public class BatchConfig(
private JobBuilderFactory factory;
public BatchConfig(JobBuilderFactory factory) {
this.factory = factory;
}
@Bean
public Step someStep {
// step implementation
}
}
我创建了以下基本测试类
@ContextConfiguration(classes=BatchConfig.class)
@SpringBootTest
public class BatchTestBase {
@Autowired
Step someStep
}
当我扩展此类并尝试运行它时,出现以下错误
BatchConfig中构造函数的参数0需要一个找不到JobBuilderFactory类型的bean
是否可以将BatchConfig
扩展到XML
或在此处添加构造函数参数来访问bean?
解决方法
创建测试上下文配置,并与需要在CKEDITOR.editorConfig = function( config ) {
config.allowedContent = true;
};
中进行测试的配置一起使用
@ContextConfiguration
,
尝试通过set而不是构造函数进行注入,如下所示:
public setFactory(JobBuilderFactory factory) {
this.factory = factory;
}