Springboot使用Jpa报错找不到bean的问题

最近搭了个Springboot,连自己的mysql好不容易连上了,发现一直报这个错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field demoRepository in com.cocal.view.InitController required a bean of type 'com.cocal.dao.DemoRepository' that could not be found.


Action:

Consider defining a bean of type 'com.cocal.dao.DemoRepository' in your configuration.

原因很简单:
在Application类加上Jpa扫描目录EnableJpaRepositories和映射的类目录EntityScan即可:

@SpringBootApplication
@ComponentScan("com.cocal")
@EnableJpaRepositories("com.cocal.dao")
@EntityScan("com.cocal.model")
public class Application {
       ......

这里先记录下,或许有更优雅的解决办法
https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot
http://blog.leanote.com/post/adrian_ye/springboot和spring-data-jpa整合时候的错误%E3%80%82)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容