最近搭了個(gè)Springboot,連自己的mysql好不容易連上了,發(fā)現(xiàn)一直報(bào)這個(gè)錯(cuò)誤:
***************************
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.
原因很簡(jiǎn)單:
在Application類加上Jpa掃描目錄EnableJpaRepositories和映射的類目錄EntityScan即可:
@SpringBootApplication
@ComponentScan("com.cocal")
@EnableJpaRepositories("com.cocal.dao")
@EntityScan("com.cocal.model")
public class Application {
......
這里先記錄下,或許有更優(yōu)雅的解決辦法
(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整合時(shí)候的錯(cuò)誤%E3%80%82)