Spring Boot with multiple datasources and in memory database
<p>I'm trying to set up Spring Boot to work with multiple datasources. I have followed the <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html" rel="nofollow">instructions</a> for setting up two datasources and set one of them primary.</p>

<pre><code>@Configuration
@EnableJpaRepositories(basePackages={"my.postgres.repositories"}
                       entityManagerFactoryRef="postgresEntitymanager"
                       transactionManagerRef="postgresTransactionManager")
public class PgConfig {
@Primary
@Bean(name="postgresDS")
@ConfigurationProperties(prefix="spring.datasource.postgres")
public DataSource postgresDataSource() {
    return DataSourceBuilder.create().build();
}
@Primary
@Bean(name="postgresEntityManager")
public LocalContainerEntityManagerFactoryBean postgresEntityManager(EntityManagerFactoryBuilder builder) {
    return builder.dataSource(postgresDataSource())
            .packages("my.postgres.domain")
            .persistenceUnit("postgresPersistenceUnit")
            .build();
}

@Primary
@Bean(name = "postgresTransactionManager")
public PlatformTransactionManager postgresTransactionManager(
        @Qualifier("postgresEntityManager") EntityManagerFactory entityManagerFactory) {
    return new JpaTransactionManager(entityManagerFactory);
}
</code></pre>

<p>I have a second configuration class for oracle which lacks the @Primary annotation but is very similar. I have also added this to my main class to exclude datasource auto configuration.</p>

<pre><code>@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
</code></pre>

<p>The problem that I'm facing is this setup doesn't allow my Integration tests that are supposed to run against an H2 databse to open a connection...</p>

<pre><code>Caused by: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection

Caused by: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
Caused by: java.sql.SQLException: The url cannot be null
</code></pre>

<p>I'm using a separate application.properties file under src/integrationtest/resources which contains</p>

<pre><code>spring.jpa.database=H2
</code></pre>

<p>How do I get my integration tests to use H2 for the repositories that I'm using when running my tests? </p>

<p>If I don't include my custom datasources everything seems to work fine.</p>

<p>Thanks</p>