How to configure two datasources with spring?

Hello,

we’re working on a springboot based camunda application. The application should write data to its own database (not the one used by the process engine).

I’ve found the docs about how to configure this: https://docs.camunda.org/manual/latest/user-guide/spring-boot-integration/configuration/#defaultdatasourceconfiguration

But there is one thing still unclear to me. According to the docs, I have to configure two DataSources and two TransactionManagers. But how can I tell to the camunda engine which TxManager it should use? In the docs, a qualifier ("camundaBpmDataSource") is only provided for the DataSource so that camunda has a chance to see that it’s the right datasource. But there is no qualifier for the TxManager. How would camunda pick the right one?

Thank you for any hints!

@fml2 you need to set the TransactionManager to the process engine configuration like below:

processEngineConfiguration.setTransactionManager(camundaTransactionManager);

@Bean
public SpringBootProcessEnginePlugin transactionManagerProcessEnginePlugin(
   @Qualifier("camundaTransactionManager") PlatformTransactionManager camundaTransactionManager) {
   return new SpringBootProcessEnginePlugin() {
       @Override
       public void preInit(SpringProcessEngineConfiguration processEngineConfiguration) {
                processEngineConfiguration.setTransactionManager(camundaTransactionManager);
       }
   };
}
1 Like

Thank you, we did it in a very similar way (but without the qualifier “camundaTransactionManager”). I just wonder why this is not in the docs (which is usually good, but misses an important detail here).

Hi @fml2,

is this the section you are looking for: https://docs.camunda.org/manual/7.13/user-guide/spring-boot-integration/configuration/#defaultdatasourceconfiguration?

Cheers, Ingo

Yes, this is the section I referenced in my original post. But it does not describe how to set the correct transaction manager in the engine (and does not even mention that it should be done).