AnsweredAssumed Answered

Multiple Data sources in activiti

Question asked by davanna on Jun 20, 2016
Latest reply on Jun 27, 2016 by jbarrez
I have written a spring boot application. I have a two data sources - one is used by activiti engine for it's database and another datasource for updating my tables. The database updates to my tables are done in the event listeners. I have configured both the data sources as follows. The code is working fine but I do sense that there may be issues here as the same default transaction manager is used by activiti engine to update it's tables and also to update my tables. This transaction manager is the JpaTransactionManager. The datasource field in the transactionmanager is pointing to my database as I have defined it as primary. The transactionfactory defined in SpringProcessEngineConfiguration is pointing to activiti datasource. The transactionFactory is used by the DbSqlSession in mybatis. I am trying to understand how Spring is updating the tables properly here as the datasources are different in both the cases.


<code language="java">

@Configuration
public class ActivitiConfiguration extends AbstractProcessEngineAutoConfiguration {

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

   @Bean(name = "activitiDataSource")
   @ConfigurationProperties(prefix = "spring.datasource.activiti")
   public DataSource getActivitiDataSource() {
      return DataSourceBuilder.create().build();
   }

   @Primary
   @Bean(name = "transactionManager")
   public PlatformTransactionManager transactionManager(@Qualifier("myDataSource") DataSource dataSource) {
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setDataSource(dataSource);
      return transactionManager;
   }

   @Bean
   public SpringProcessEngineConfiguration springProcessEngineConfiguration(PlatformTransactionManager activitiTransactionManager,
         SpringAsyncExecutor springAsyncExecutor, @Qualifier("activitiDataSource") DataSource dataSource) throws IOException {

      return baseSpringProcessEngineConfiguration(dataSource, activitiTransactionManager, springAsyncExecutor);
   }

}

</code>

Outcomes