1

I'm trying to configure two datasources in my spring batch application. One for batch metadata tables, and another for the business tables.

Snippet from my application.properties file:

#primary datasource (Azure SQL server)
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=

#batch datasource(Azure SQL Server)
spring.batchdatasource.url=
spring.batchdatasource.username=
spring.batchdatasource.password=
spring.batchdatasource.driver-class-name=

DataSourceConfig class:

@Configuration
public class DataSourceConfig {

    @Bean(name = "batchDatasource")
    @ConfigurationProperties(prefix="spring.batchdatasource")
    public DataSource batchDataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "primaryDatasource")
    @ConfigurationProperties(prefix="spring.datasource")
    @Primary
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
}

SpringBatchConfig class:

@Configuration
public class SpringBatchConfig extends DefaultBatchConfigurer{

    @Autowired
    private JobBuilderFactory jobs;

    @Autowired
    private StepBuilderFactory steps;


    @Qualifier("batchDataSource")
    @Autowired
    private DataSource batchDataSource;

    @Autowired
    private PlatformTransactionManager transactionManager;


    @Override
    public JobRepository createJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(batchDataSource);
    factory.setTransactionManager(transactionManager);
    factory.setTablePrefix("schema1"+ ".BATCH_");
    factory.afterPropertiesSet();
    return factory.getObject();
    }

 /* step and job beans here */
}

My main class is the one annotated with @EnableBatchProcessing

@SpringBootApplication
@EnableBatchProcessing
public class SpringBatchExample1Application {

    public static void main(String[] args) {
         SpringApplication.run(SampleApplication.class, args);
    }
}

I faced the following exeption:

Error creating bean with name 'springBatchConfig': Invocation of init method failed; nested exception is org.springframework.batch.core.configuration.BatchConfigurationException: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.

Based on this answer, I changed my url property names as follows:

spring.datasource.jdbc-url=

spring.batchdatasource.jdbc-url=

Though it solved the jdbcUrl error, it posed another issue:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Reference to database and/or server name in 'sample-sql-server.schema1.MY_TABLE_NAME' is not supported in this version of SQL Server.

Both my data sources are Azure SQL server instances. I looked up and found it was not possible to use multiple Azure SQL databases years ago, but based on this question it should not be the case anymore.

CtrlAltElite
  • 487
  • 8
  • 32
  • try changing ODBC with a newer one – Alberto Sinigaglia Jul 08 '21 at 22:20
  • ​Could you please let us know if you trying to use linked server or cross-database query, as far we could see from the error message it says the same, but would request you to refer : https://dba.stackexchange.com/questions/170828/delete-records-from-single-azure-db-table-that-has-no-linking-reference-to-dat-- might help, and if possible to share more details on how you are trying to query data. – IpsitaDash-MT Jul 20 '21 at 10:25

0 Answers0