title: Error creating bean with name 'batchDataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
body: <p>I have a batch configuration. I saw the batch process is default using <code>InMemoryMap</code>. Instead I need to use the MySQL to send all the execution details by Batch. But when I use the following code I am getting the following error,</p>
  <blockquote>
  <p>Error creating bean with name 'batchDataSource': Requested bean is
  currently in creation: Is there an unresolvable circular reference?</p>
  </blockquote>
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class BatchProcess extends DefaultBatchConfigurer {
  
      private @Autowired Environment env;
  
      @Bean
      @StepScope
      public ItemReader reader() {
          ...
      }
  
      @Bean
      @StepScope
      public ItemProcessor processor() {
          ...
      }
  
      @Bean
      @StepScope
      public ItemWriter writer() {
          ...
      }
  
      @Bean
      @Primary
      public DataSource batchDataSource() {
          HikariDataSource hikari = new HikariDataSource();
          hikari.setDriverClassName(env.getProperty(&quot;spring.datasource.driver-class-name&quot;));
          hikari.setJdbcUrl(env.getProperty(&quot;spring.datasource.url&quot;));
          hikari.setUsername(env.getProperty(&quot;spring.datasource.username&quot;));
          hikari.setPassword(env.getProperty(&quot;spring.datasource.password&quot;));
          return hikari;
      }
  
      public JobRepository getJobRepository() {
          JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
          factory.setDataSource(batchDataSource());
          factory.setTransactionManager(manager());
          factory.afterPropertiesSet();
          return factory.getObject();
      }
  
      public PlatformTransactionManager manager() {
          return new ResourcelessTransactionManager();
      }
  
      @Bean
      public Step step() {
          return stepBuilderFactory.get(&quot;step&quot;)
                  .chunk(1000)
                  .reader(reader())
                  .processor(processor())
                  .writer(writer())
                  .build();
      }
  
      @Bean
      public Job job() {
          return jobBuilderFactory.get(&quot;job&quot;)
                  .flow(step())
                  .end()
                  .build();
      }
  
      @Bean
      public JobLauncher getJobLauncher() {
          SimpleJobLauncher launcher = new SimpleJobLauncher();
          launcher.setJobRepository(createJobRepository());
          return launcher;
      }
  }
  </code></pre>
  <p>In property file I am using,</p>
  <pre><code>spring.batch.job.enabled=false
  spring.batch.initialize-schema=always
  </code></pre>
  <p>So what I missed? I am using JPA. And even why it is not using available JPA datasource? How can I force the Spring batch to use default MySQL instead InMemoryMap?</p>