0

I have following code to enable the JPA repository scan, but I have many packages in my project, is it able to set basePackages in a property file? as I don't want to change this class EntityManagerConfig in this class.

config file:

  • com.mycompany.trades.jpa
  • com.mycompany.system.jpa
  • com.mycompany.crm.jpa
    @EnableJpaRepositories(basePackages = { "com.mycompany.system.jpa" }, entityManagerFactoryRef = "emf")
    @EntityScan("com.mycompany.system.jpa")
    public class EntityManagerConfig {
      //...
    }
meadlai
  • 895
  • 1
  • 9
  • 22
  • You could just have it scan all of `com.mycompany`. – Andreas Mar 03 '20 at 00:02
  • 1
    Recommended read: [What are the uses of `@EntityScan` and `@EnableJpaRepositories` annotations?](https://springbootdev.com/2017/11/13/what-are-the-uses-of-entityscan-and-enablejparepositories-annotations/) – Andreas Mar 03 '20 at 00:05
  • Thanks @Andreas what if there is another package with name started from "org.some_org.*", It is able to scan the root path with empty "" setting but it will take a long time. – meadlai Mar 19 '20 at 05:43
  • 1
    You can specify more than one name, e.g. `basePackages = { "com.mycompany", "org.some_org" }`. That's why the `{ }` are there, it's an array of values, as you can also see in the [documentation](https://docs.spring.io/spring-data/data-jpa/docs/current/api/org/springframework/data/jpa/repository/config/EnableJpaRepositories.html#basePackages--): `String[]` – Andreas Mar 19 '20 at 18:04

0 Answers0