0

Application has a default spring data source specified in application.yml

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:oracle:thin:@localhost:1521:xe
    username: system
    password: oracle
    hikari:
      poolName: Hikari
      auto-commit: false

I have added configuration options for a second data source, used for a completely difference (JDBCTemplate purpose).

faas20:
  ds:
    url: jdbc:oracle:thin:@tldb0147vm.group.net:1760:tdb
    username: ...
    password: ...

Then, I add two data sources, one named, and the other default. Without the default one, liquibase fails to start.

@Configuration
public class LegacyConfiguration {

    @Bean(name = "faas20")
    @ConfigurationProperties(prefix = "faas20.ds")
    public DataSource legacyDataSource() {
        return DataSourceBuilder
            .create()
            .build();
    }

    @Bean
    public DataSource defaultDataSource() {
        return DataSourceBuilder
            .create()
            .build();
    }

}

Startup of the application fails though. The application now cannot build the default EntityManagerFactory.

Why would that be affected?

Parameter 0 of constructor in impl.OrderServiceImpl required a bean named 'entityManagerFactory' that could not be found.
Consider defining a bean named 'entityManagerFactory' in your configuration.

Without the two data sources present the application and liquibase start up as they should.

edit

I am not clear on how to configure two separate data sources,

  1. Default Data Source for JPA
  2. Additional Data Source for use in JDBC (and potentially other JPA classes)
Jim
  • 14,952
  • 15
  • 80
  • 167
  • Are you using spring-boot-starter-data-jpa? You could @Autowired the default spring datasource instead of rolling your own with DataSourceBuilder – camtastic Sep 11 '19 at 21:13
  • yes, I am using spring-boot-starter-data-jpa, but it is unclear to me how I configure two separate data sources, 1 default JPA datasource, and another that I can inject via a name or some other mechanism. – Jim Sep 16 '19 at 05:44
  • Looks like the default datasource is missing @Primary and @ConfigurationProperties(prefix="spring.datasource") see https://stackoverflow.com/a/30344608/7105883 – camtastic Sep 16 '19 at 13:04

0 Answers0