使用@atuowired注解无法注入bean的解决方法(出现Field userMapper in com.peng.service.Impl.UserServiceImpl required a bean of type ‘com.peng.dao.UserMapper’ that could not be found.The injection point has the following annotations:@org.springframework.beans.factory.annotation.Autowired(required=true)
在service层中使用@Autowired注解自动注入UserMapper时出现错误
出现这种错误可能会有几种解决方法
一、可能是pom.xml中没有引入mybatis
二、可能是Mapper接口没有使用@Mapper注解标注或者启动类中可以使用MapperScan注解标注Mapper的路径
三、如果都不是前两种问题,那就可能是第三种,我就是第三种,正如他提示那样Autowired(required=true),可能是Autowired中的required属性出错,所以我们可以指定Autowired中的这个属性为false测试一下。果然,将这个属性指定为false之后,服务器已经可以正常启动了。
**注意:**将这个属性指定为false之后,有可能会出现新的问题,服务器启动不会报错了,但是当你执行之后,你会发现UserMapper为null,使用usermapper时会报空指针错误
目前楼主还没有找到解决方法,找到会继续在这里更新
楼主找到原因了,是因为mybatis的版本问题,mybatis的版本和其他的版本不适配,所以出现不适配,各位读者如果出现这个问题,请关注一下maven中各依赖的版本问题