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??

1

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.