1

I trying to use two databases in my project so i follow this link:

this link

but just like example i create one Interface and extend CrudRepository

public interface UsuarioRepository extends CrudRepository<TbUsuario, Long>{}

so where i use?

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

@Bean
@ConfigurationProperties(prefix="spring.secondDatasource")
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
} 

to specify my datasource??

Community
  • 1
  • 1
Fabio Ebner
  • 2,209
  • 11
  • 36
  • 62
  • Here is a good example on [how to configure jpa repositories using different datasource and transaction manager](http://www.baeldung.com/spring-data-jpa-multiple-databases) – Eduardo Sanchez-Ros Jan 14 '16 at 14:33

1 Answers1

1

You need to configure two Datasources, two EntityManagerFactories, and two TransactionManagers. Have a look at section 67.7 Use Two EntityManagers in the Spring Boot docs and 4.1.2. Annotation based configuration in the Spring Data JPA docs. You also need to disable datasource auto configuration in the Application class. An example showing how to put all this stuff together can be found here. Good luck!

Alexandre
  • 36
  • 5