4

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

1 Answer 1

2

Your problem is not related to mvc module, but is more related to data access layer.

Making it simple, you need to configure 2 different datasources, with respective entity manager and transaction manager.

Then in your dao classes you can inject the needed entity manager.

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

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

Searching on google you can best find your needs, depending on which module you are using in data layer. One suggestion is to take a look at spring data module, it abstracts a lot of things.

Here an example of an xml configuration of multiple datasources with spring data: https://github.com/spring-projects/spring-data-jpa/blob/master/src/test/resources/multiple-entity-manager-integration-context.xml

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.