I have a module A that has its own EntityManager em. This module is a dependency in other module B. Module B interacts with two instances of same db,and based on business logic I decide which record to store in which db. For this I have two entity managers em1 and em2. On deploying the error comes like:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.moduleA.moduleAclass com.moduleA.moduleAclass; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'moduleAclass': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single matching bean but found 3: em,em1,em2.
Why is module B not independent of the EntityManager of the dependent modules? What should be the correct way?
configurations for module A
persistence.xml for module A
for some reason all the entities of moduleA, we keep in moduleAentities-persistence.xml
Configuration for module B which has to interact with two instances of the same database.
persistence.xml of module B
Class in module B that provides me the entity managers at runtime
On deployment, we get exceptions for module A like expected single matching bean but found 3: em,em1,em2. Its not able to resolve which entitymanager should be used for moduleA. My question is, since module A is added as a dependency in module B, its entity managers should be independent of module B.