spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Can't wrap JobRepository in a tracing representation

Open marcingrzejszczak opened this issue 4 years ago • 0 comments

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 JobRepository not the concrete one
  • do not create JobBuilderFactory nor StepBuilderFactory via new.

marcingrzejszczak avatar Apr 30 '21 11:04 marcingrzejszczak