最近搭了个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)