cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti with Spring Boot and two datasources

sebljun
Champ in-the-making
Champ in-the-making
I have set up a project with the Activiti Spring Boot configuration. Because I don't want to pollute the Activiti db with the tables related to the business logic of this application, I have set up two data sources:


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

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


The appDataSource is marked as primary since I plan to make use of the autoconfig of JPA with it. What I'm wondering is how to configure Activiti to pick up the secondary activitiDataSource instead of appDataSource. Someone has posted a very similar and unanswered  question on Stack Overflow.
2 REPLIES 2

trademak
Star Contributor
Star Contributor
In the process engine configuration you can specify the datasource name. But in combination with Spring Boot I don't know the answer immediately. Did you look into the source code, how the Activiti process engine configuration is created with Activiti Spring Boot?

Best regards,

sebljun
Champ in-the-making
Champ in-the-making
I did now and found the configuration in DataSourceProcessEngineAutoConfiguration.

By adding this class I managed to override the default configuration and specify what data source I wanted with @Qualifier:

<java>
@Configuration
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class ActivitiDatasourceConfiguration extends AbstractProcessEngineAutoConfiguration {
    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(
            @Qualifier("activitiDataSource") DataSource dataSource,
            PlatformTransactionManager transactionManager,
            SpringAsyncExecutor springAsyncExecutor) throws IOException {
        return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
    }
}
</java>

I do not know if this is the appropriate way to do this but so far it has worked for me.

As an aside the Flyway Spring Boot integration solves this problem in a convenient way. The desired datasource is simply annotated with @FlywayDataSource. If there is interest for a similar solution, I might make an attempt at creating a pull request.