1

As pointed out here, you can define two Datasources in Spring Boot in the following way:

#first db
spring.datasource.url = [url]
spring.datasource.username = [username]
spring.datasource.password = [password]
spring.datasource.driverClassName = oracle.jdbc.OracleDriver

#second db ...
spring.secondDatasource.url = [url]
spring.secondDatasource.username = [username]
spring.secondDatasource.password = [password]
spring.secondDatasource.driverClassName = oracle.jdbc.OracleDriver


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

@Bean
@ConfigurationProperties(prefix="spring.secondDatasource")
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
}

This seems to work fine. But when you are doing Atomikos XA-Transactions, each datasource has to has a unique resource name for the case that a recovery is necessary.

The Boot documentation defines a property for this:

spring.jta.atomikos.datasource.unique-resource-name=dataSource # The unique name used to identify the resource during recovery.

How do I provide a unique-resource-name for the primary and a different one for the secondary resource in Spring Boot?

Looks to me like XA-Transactions are supported in Boot, but only between JMS and DB ressources...

Community
  • 1
  • 1
Dirk
  • 1,064
  • 1
  • 11
  • 13

0 Answers0