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).
문제
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 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})
to Application
, but without success.
What am I doing wrong?
해결책
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).
다른 팁
You must locate entities and repositories pakages by using
@EnableJpaRepositories(basePackages = "your.repositories.pakage")
@EntityScan(basePackages = "your.entities.pakage")
this is what worked for me :
@EnableJpaRepositories(basePackages ={ "package1","package2"})
@EntityScan(basePackages ={ "package3","package4"})
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.*"})