I have configured two persistent units with the entity managers set up as show below:
In your @Configuration file, if this is your dataSource:
@Bean(name = "dataSource")
public DataSource getDataSource() {
return DataSourceBuilder
.create()
.username(username)
.password(password)
.url(url)
.build();
}
this would be your transaction manager bean:
@Bean(name = "DataSourceTransactionManager")
public DataSourceTransactionManager getDataSourceTransactionManager() {
return new DataSourceTransactionManager(getDataSource());
}
Then annotate the service method you would like to be transactional:
@Transactional(transactionManager = "DataSourceTransactionManager", timeout = 60, rollbackFor = { Exception.class})