1

In our current XML based configuration, we have setup for multiple repositories like below:

    <jpa:repositories base-package="com.grc.riskanalysis.repository.master" transaction-manager-ref="transactionManager"
                  entity-manager-factory-ref="entityManagerFactory"/>
    <jpa:repositories base-package="com.grc.riskanalysis.repository.slave" transaction-manager-ref="transactionManager2"
                  entity-manager-factory-ref="dynamicEntityManagerFactory"/>

I am trying to migrate this XML configuration to class based configuration, but it is not allowing to have multiple @EnableJpaRepositories annotations. How to achieve this with class based (annotation based) configuration ?

Ram
  • 423
  • 4
  • 26
  • 1
    You can have as many `@EnableJpaRepositories` annotations as you want, just place them on seperate `@Configuration` classes. That way you can also seperate the different JPA configurations for the datasource/txmanager/entitymanagerfactory. – M. Deinum Dec 11 '19 at 07:36
  • Yes, I found same solution in below links( mentioned in my answer) – Ram Dec 11 '19 at 08:06

2 Answers2

2

@EnableJpaRepositories has a parameter named basePackages. It accepts an array of strings and you can use that to add your packages.

Something like the following will do

@EnableJpaRepositories(basePackages = {"package1", "package2"})

aksappy
  • 3,400
  • 3
  • 23
  • 49
0

I found the answer from the below two posts, seems need to write separate configuration class for each JPA.

baeldung

Enable Multiple JPA Repositories

Ram
  • 423
  • 4
  • 26