Spring Boot with multiple database using hibernate and JpaRepository -
how implement multiple database configurations in spring boot ??? how create spring boot mvc application 2 different databases using hibernate ???
application.properties(db1=core,db2=staging)
server.port=8772 spring.core.driverclassname=com.mysql.jdbc.driver spring.core.url=jdbc:mysql://ip:port/coredb spring.core.username=uname spring.core.password=pwd spring.staging.driverclassname=com.mysql.jdbc.driver spring.staging.url=jdbc:mysql://ip:port/stagingdb spring.staging.username=uname spring.staging.password=pwd
repository :
public interface istagingentitydao extends jparepository<stagingemployee, integer>{ query("select e stagingemployee e") public list<stagingemployee> getentitydata(); }
dbconfig :
public class dbconfig { @bean(name="stagingdatasource") @primary @configurationproperties(prefix="spring.staging") public datasource stagingdatasource() { return datasourcebuilder.create().build(); } @bean(name="coredatasource") @configurationproperties(prefix="spring.core") public datasource coredatasource() { return datasourcebuilder.create().build(); } }
requirement :
i want copy data 1 db consider employee entity want copy data db1 db2 have done far have create controller(@restcontroller) , service , repository data db 1 , push in db2 calling respective service in single spring boot app itself.
exception : cannot determine embedded database driver class database type none. if want embedded database please put supported 1 on classpath.
whats missing in above configurations ????
i think can find usefull
http://docs.spring.io/spring-boot/docs/current-snapshot/reference/htmlsingle/#howto-two-datasources
it shows how define multiple datasources & assign 1 of them primary.
here rather full example, contains distributes transactions - if need it.
what need create 2 configuration classes, separate model/repository packages etc make config easy.
also, in above example, creates data sources manually. can avoid using method on spring doc, @configurationproperties annotation. here example of this:
http://xantorohara.blogspot.com.tr/2013/11/spring-boot-jdbc-with-multiple.html
hope these helps
Comments
Post a Comment