社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
今天启动写的demo报如下错误,是类加载不到的问题,以前没遇到过,所以就尝试解决。报错信息如下:
Description:
Field userDao in com.example.swaggerDemo.service.serviceImpl.UserServiceImpl required a bean of type 'com.example.swaggerDemo.Dao.UserDao' that could not be found.
Action:
Consider defining a bean of type 'com.example.swaggerDemo.Dao.UserDao' in your configuration.
最后解决办法为:在springbootApplication启动类里添加扫描注解即可,因为本项目用的MyBatis mapper interfaces,所以用了@MapperScan解决了,如下:
@MapperScan("com.example.swaggerDemo.Dao")
由此受到启发,同理,以后遇到类似问题可在启动类上加扫描类注解,例如@ComponentScan等,扫描的路径即类所在的文件路径即可。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!