带有JPA的Spring Boot:将@Entity移到其他包中 [英] Spring Boot w/ JPA: move @Entity to different package
问题描述
我在使用Spring-Boot和JPA的第一步时遇到了麻烦.我从使用Gradle的一个非常简单的来自Git的示例开始.
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.
现在简单地将Customer
移至另一个程序包,比如说hello2
会导致异常Caused by: java.lang.IllegalArgumentException: Not an managed type: class hello2.Customer
.我尝试添加
Now simply moving Customer
to another package, let's say to hello2
results in an exception Caused by: java.lang.IllegalArgumentException: Not an managed type: class hello2.Customer
. I tried to add
@ComponentScan(basePackageClasses= {Customer.class}) // AND OR
@EnableJpaRepositories(basePackageClasses= {Customer.class})
@ComponentScan(basePackageClasses= {Customer.class}) // AND OR
@EnableJpaRepositories(basePackageClasses= {Customer.class})
到Application
,但没有成功.
我在做什么错了?
推荐答案
Location of entities in Spring Boot can be configured using @EntityScan
.
默认情况下,@EnableAutoConfiguration
启用实体扫描所在的包(如果它不是默认包).
By default, @EnableAutoConfiguration
enables entity scanning in the package where it's placed (if it's not a default package).
这篇关于带有JPA的Spring Boot:将@Entity移到其他包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!