In Spring MVC, How to connect to two databases (Mysql database and MongoDB) in the same project? if possible

In Spring MVC, How to connect to two databases (Mysql database and MongoDB) in the same

+4
source share
1 answer

Your problem is not related to the mvc module, but more related to the level of data access.

Simply put, you need to configure 2 different data sources, with the appropriate entity manager and transaction manager.

Then in your dao classes you can enter the necessary entity manager.

@PersistenceContext(unitName="entityManager1")
private EntityManager entityManager1;

@PersistenceContext(unitName="entityManager2")
private EntityManager entityManager2;

google , , . - spring, .

xml- spring: https://github.com/spring-projects/spring-data-jpa/blob/master/src/test/resources/multiple-entity-manager-integration-context.xml

+2

All Articles