Help Needed For Multiple Datasources in Spring Boot

I’ve been following the documentation here:

But alas I keep running into issues:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration': Unsatisfied dependency expressed through field 'processEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngineFactoryBean': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.

I understand the error, but according to the docs if I have a data source with the name camundaBpmDataSource it should use that instead of dataSource bean.

@Configuration
@EnableTransactionManagement
public class SecondaryDatasourceConfiguration {

    @Bean(name = "camundaBpmDataSource")
    @ConfigurationProperties(prefix = "spring.camunda-datasource")
    public DataSource camundaBpmDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "camundaTransactionManager")
    public PlatformTransactionManager camundaTransactionManager(@Qualifier("camundaBpmDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}
package solutions.iscout.config;

import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        basePackages = {"solutions.iscout.primary-domain.repo"},
        entityManagerFactoryRef = "primaryEntityManagerFactory",
        transactionManagerRef = "primaryTransactionManager"
)
public class PrimaryDatasourceConfiguration {

    public static final String PERSISTENCE_UNIT_NAME = "PRIMARY";

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

    @Primary
    @Bean(name = "primaryEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("primaryDataSource") DataSource dataSource) {
        return new LocalContainerEntityManagerFactoryBean() {{
            setDataSource(dataSource);

            setJpaDialect(new HibernateJpaDialect());

            final Properties jpaProperties = new Properties();

            jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServer2012Dialect");
            jpaProperties.setProperty("hibernate.ddl-auto", "none");

            setJpaProperties(jpaProperties);
            setPersistenceProviderClass(HibernatePersistenceProvider.class);
            setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
            setPackagesToScan("solutions.iscout.primary-domain.domain");
        }};
    }

    @Primary
    @Bean(name = "primaryTransactionManager")
    public PlatformTransactionManager transactionManager(@Qualifier("primaryEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

}

Any input and direction would be greatly appreciated!

@James_Gilchrist did you find a solution? I’m in the same situation :slight_smile:

Show your properties, problem is there

My issue was solved by changing the variable in the yaml for datasource to “jdbcUrl” instead of “url”

jdbcUrl: jdbc:mysql://databaseUrl
username: root
password: root