spring boot mybatis


APPLICATION FAILED TO START


Description:

The bean ‘userMapper’ could not be injected because it is a JDK dynamic proxy

The bean is of type ‘com.sun.proxy.$Proxy67’ and implements:
com.example.demomybatis.mapper.UserMapper

Expected a bean of type ‘com.example.demomybatis.service.UserService’ which implements:
com.baomidou.mybatisplus.extension.service.IService

的bug 原因

@Resource 找到了错误的注入对象:

代码如下:
在这里插入图片描述
这里我实际对象时 UserService 但是 名称确是 userMapper
由于 @Resource 首先会根据 name 导入,所以,这里就会讲 UserMapper 导入到 这个对象。如果名字没

修复办法有三种:

方法一:修改 userMapper 成 userService 当然也可以是其他名字,只有不和其他尸体了重名就行。
在这里插入图片描述

方法二:
将 @Service @Resource 都明确指定 名字

@Service("UserService")  @Resource(name = "UserService")

方法三:
使用 @Autowired 注解 替换 @Resource 注解


版权声明:本文为zhanglinlang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。