有没有办法扩展@Configuration类以包括构造函数参数?

问题描述

我正在为一个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;
 }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...