При получении ошибки не удается зарегистрировать конфигурацию задания, поскольку DuplicationJobException после обновления до Spring 2.x
Уже проверено, в моем коде нет повторяющегося имени.
Ошибка
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:558)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobCalcSampleDetail' defined in class path resource [id/co/a/microservice/batch/job/SampleJobConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.FatalBeanException: Cannot register job configuration; nested exception is org.springframework.batch.core.configuration.DuplicateJobException: A job configuration with this name [jobCalcSampleDetail] was already registered
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at id.co.a.microservice.batch.NcsBatchServiceApplication.main(NcsBatchServiceApplication.java:15)
... 6 more
Caused by: org.springframework.beans.FatalBeanException: Cannot register job configuration; nested exception is org.springframework.batch.core.configuration.DuplicateJobException: A job configuration with this name [jobCalcSampleDetail] was already registered
at org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor.postProcessAfterInitialization(JobRegistryBeanPostProcessor.java:150)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:429)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
... 21 more
Caused by: org.springframework.batch.core.configuration.DuplicateJobException: A job configuration with this name [jobCalcSampleDetail] was already registered
at org.springframework.batch.core.configuration.support.MapJobRegistry.register(MapJobRegistry.java:52)
at org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor.postProcessAfterInitialization(JobRegistryBeanPostProcessor.java:146)
... 24 more
Код конфигурации задания
@Configuration
@EnableBatchProcessing
public class SampleJobConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public PostgresDbConfig postgres;
@Value("${xxx.chunk.default}")
private int chunkSize;
@Value("${xxx.limit.retry}")
private int retryLimit;
@Bean
@StepScope
public Tasklet taskletRmvSample(@Value("#{jobParameters['period']}") String period,
@Value("#{jobParameters['clearData']}") Boolean clearData) {
return (StepContribution stepContribution, ChunkContext chunkContext) -> {
if (clearData) {
new JdbcTemplate(postgres.dataSource()).execute("");
}
return RepeatStatus.FINISHED;
};
}
@Bean
public Step step1RmvSample() {
return stepBuilderFactory.get("step1RmvSampleDetail").tasklet(
taskletRmvSample(null, null)).build();
}
@Bean
public Job jobCalcSampleDetail() throws Exception {
return jobBuilderFactory.get("jobCalcSampleDetail").incrementer(new RunIdIncrementer()).start(
step1RmvSample()).build();
}
}
Основной прикладной код
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
public class NcsBatchServiceApplication {
public static void main(String[] args) {
SpringApplication.run(NcsBatchServiceApplication.class, args);
}
}
Используется родительский загрузочный пружин 2.1.4 - Core Batch Core 4.1.1
ранее он работал нормально при использовании пружины 1.5.17, но после обновления до пружины 2. * ошибка.
Также пытался добавить make modular, но все равно ошибка
@EnableBatchProcessing(modular = true)
Структура пакета image
Может быть, кто-то может помочь.
Спасибо