SpringBoot报错
Description:
Field userDao in com.example.provider8001.service.UserServiceImpl required a bean of type 'com.example.provider8001.dao.UserDao' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.provider8001.dao.UserDao' in your configuration.
这里说bean找不到。
解决方法:
1.查看service层是否添加@Service注解
我这里添加了,没有问题。。。那么下一步。
2.在启动类上增加@ComponentScan(basePackages = {"com.**.**.pojo"})注解。告诉它你的bean在这里。
3.添加@MapperScan(basePackages = "com.example.provider8001.dao",markerInterface = UserServiceImpl.class),注解。(这里有个坑,在添加注释后能够进行正常运行,但是访问后显示404。)
我这里曾多次尝试, ComponentScan(basePackages={"com.**.**"});ComponentScan(basePackageClasses={User.class})...包括MapperScan注解。在途中,它给我报出过其他错误。当时正以为我快要见到黎明的曙光!!!
然后它又回到了
Description:
Field userDao in com.example.provider8001.service.UserServiceImpl required a bean of type 'com.example.provider8001.dao.UserDao' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.provider8001.dao.UserDao' in your configuration.
辗转反侧,夜不能寐。。。
4.查询配置是否有问题(以上步骤访问出现404时)
5.查询maven导包是否兼容。
这一步很关键。。。。(以头抢墙尔)
查询参考文档
Unsatisfied dependency expressed through field 'xxxService'_慕课手记 (imooc.com)