spring-batch
spring-batch copied to clipboard
Can't wrap JobRepository in a tracing representation
The problem
I can't wrap the JobRepository used by JobBuilderFactory or StepBuilderFactory, the default one is being used.
Same type of a problem as presented here https://github.com/spring-projects/spring-batch/issues/816 .
related Sleuth code: https://github.com/spring-cloud/spring-cloud-sleuth/blob/issues_%231904_batch_with_job_repository/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/batch/TraceBatchAutoConfiguration.java#L57-L60
Implementation issues
AbstractBatchConfiguration creates JobBuilderFactory and StepBuilderFactory as fields.
@Override
public void afterPropertiesSet() throws Exception {
this.jobBuilderFactory = new JobBuilderFactory(jobRepository());
this.stepBuilderFactory = new StepBuilderFactory(jobRepository(), transactionManager());
}
JobRepository is being injected directly to it from the method bean defitinion
@Bean
public abstract JobRepository jobRepository() throws Exception;
Potential solutions
- do not expose the bean unconditionally
- inject any
JobRepositorynot the concrete one - do not create
JobBuilderFactorynorStepBuilderFactoryvianew.