小编Vim*_*wan的帖子

春季批次中的覆盖 Bean 问题

我有一个 spring 批处理应用程序,我必须在其中覆盖像 jobLauncher 这样的 bean。但是当我尝试运行命令 clean install 时,我遇到了 bean 覆盖问题。它在我的本地机器上运行良好,但我在 Jenkins 上遇到了问题,我不知道为什么它没有发生在我的本地机器上。

我查看了他们正在扩展配置类并覆盖 bean 的 spring 代码。我尝试扩展 SimpleBatchConfiguration 类,但遇到了一些问题,我认为这不是一个好主意。

JobLaunher Bean in Application:

    @Bean
    public JobLauncher jobLauncher(JobRepository jobRepository) throws Exception {
        SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
        jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
        jobLauncher.setJobRepository(jobRepository);
        jobLauncher.afterPropertiesSet();
        return jobLauncher;
    }

JobLauncher in Spring Batch:

    @Override
    @Bean
    public JobLauncher jobLauncher() throws Exception {
        return createLazyProxy(jobLauncher, JobLauncher.class);
    }

Error Logs:


APPLICATION FAILED TO START
***************************

Description:

The bean 'jobLauncher', defined in com.orange.alc.dabek.dataload.config.BatchConfiguration, could not be registered. A bean …
Run Code Online (Sandbox Code Playgroud)

java spring spring-batch spring-boot

3
推荐指数
1
解决办法
4168
查看次数

标签 统计

java ×1

spring ×1

spring-batch ×1

spring-boot ×1