带有JPA的Spring Boot:将@Entity移到其他包中 [英] Spring Boot w/ JPA: move @Entity to different package

查看:298
本文介绍了带有JPA的Spring Boot:将@Entity移到其他包中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用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,但没有成功.

我在做什么错了?

推荐答案

Spring Boot中实体的位置可以使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆