Spring Boot w/ JPA: move @Entity to different package

前端 未结 4 955
死守一世寂寞
死守一世寂寞 2020-12-28 14:03

I\'m having trouble with my first steps using Spring-Boot with JPA. I\'ve started with a pretty minimalistic example from Git using Gradle.

Now simply moving

相关标签:
4条回答
  • 2020-12-28 14:21

    Location of entities in Spring Boot can be configured using @EntityScan.

    By default, @EnableAutoConfiguration enables entity scanning in the package where it's placed (if it's not a default package).

    0 讨论(0)
  • 2020-12-28 14:28

    Giving same package location (i.e base package) for below annotation worked for me :-

    @SpringBootApplication(scanBasePackages = {"org.ashu.java.*"})
    @EnableJpaRepositories(basePackages ={ "org.ashu.java.*"})    
    @EntityScan(basePackages ={ "org.ashu.java.*"})
    
    0 讨论(0)
  • 2020-12-28 14:31

    You must locate entities and repositories pakages by using

    @EnableJpaRepositories(basePackages = "your.repositories.pakage")
    
    @EntityScan(basePackages = "your.entities.pakage")
    
    0 讨论(0)
  • 2020-12-28 14:33

    this is what worked for me :

    @EnableJpaRepositories(basePackages ={ "package1","package2"})
    @EntityScan(basePackages ={ "package3","package4"})
    
    0 讨论(0)
提交回复
热议问题