1

I am building a stand alone java application using Spring JPA frame work. I am able to access the DB in below scenario: if I give the DB details in application.properties file as

spring.datasource.url=******** spring.datasource.username=******
spring.datasource.password=******

then it's working properly.

but I have to create two DB connections in the same application so, I changes the names as below

spring.Datasource1.url=********* spring.Datasource1.username=******
spring.Datasource1.password

spring.Datasource2.url=************ spring.Datasource2.username=****
spring.Datasource2.password=*****

then it's not working.

Can you please provide the solution for it?

I have uploaded my code base in below location. https://github.com/nagtej/MultipleDataSource

1 Answer 1

3

This might be helpful to you http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-two-datasources

Also, to connect to multiple data sources you would need to manually configure a DataSource, EntityManagerFactory and JpaTransactionManager.

For this, you can have a look at code placed at https://github.com/spring-projects/spring-data-examples/tree/master/jpa/multiple-datasources

Another good example for this is shared at http://xantorohara.blogspot.com.au/2013/11/spring-boot-jdbc-with-multiple.html

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

2 Comments

instead of links I suggest you give the answer a bit more body, link only answers aren't encouraged.
Thanq So much for your answer. it fix my problem. here i have doubt that, when we are using multiple data source, how the repository will know to which DB it need to connect. Can you please me tell me that.

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.