'Unable to run a batch job. Error: java.lang.IllegalStateException: To use a class the context must contain precisely one, found 2

Getting error message while executing a batch job in Spring4 application.

Initialization of bean failed; nested exception is java.lang.IllegalStateException: To use a class the context must contain precisely one, found 2 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'job' defined in class path resource [test.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: To use a custom batchClass the context must contain precisely one, found 2

Fetch datasource details from the property file:

test.jdbc.kite.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
test.jdbc.kite.url=test
test.jdbc.kite.username=KITELILLE
test.jdbc.kite.password=testDriver
test.jdbc.batch.url=url
test.jdbc.batch.username=user1
test.jdbc.batch.password=password1
test.jdbc.url=testUrl
  

The source code:

    @Override   
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSourceBatch);
        factory.setTransactionManager(this.getTransactionManager());
        factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    public  Job job(Step stepSynchroSdg) {
        return jobBuilderFactory.get("test").incrementer(new CustomRunIdIncrementer())
        .....       
    }

Any idea to resolve the issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source