java – Spring无法找到JpaRepository
发布时间:2020-12-15 01:37:24 所属栏目:大数据 来源:网络整理
导读:使用JavaConfig我在查找@Repository Spring bean时遇到问题. 存储库接口定义如下: @Repositorypublic interface UserRepository extends JpaRepository 配置定义如下: @Configuration@ComponentScan("com.example")@EnableAutoConfiguration@EnableJpaRepo
使用JavaConfig我在查找@Repository Spring bean时遇到问题. 存储库接口定义如下:
配置定义如下:
包结构如下所示:
在日志文件中,我看到存储库被认为是bean定义的候选者,但是:
趣味事实 如果我将SampleApplication类移动到com.example包,一切都会开始工作. 我缺少什么想法? 最佳答案
如果JPA实体不在com.example.configuration的子包中,则可能需要使用Spring Boot的@EntityScan注释.我还建议您将@Configuration从SpringBootServletInitializer移到自己的类中.
如果您可以将配置类上移到某个级别,则可以同时删除@ComponentScan,@ EnableJpaRepositories和@EntityScan注释(请参阅http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-locating-the-main-class) 如果@EntityScan没有解决问题,也许您可??以提供我们可以查看的示例项目? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |