小工具知识网

当前位置: 首页 > 行业知识 > 启动项目报错:The bean ‘XXXXMapper‘ could not be injected because it is a JDK dynamic proxy

行业知识

启动项目报错:The bean ‘XXXXMapper‘ could not be injected because it is a JDK dynamic proxy

2026-12-05 10:36:17 来源:互联网转载

Description:

()

The bean 'studentMapper' could not be injected because it is a JDK dynamic proxy

The bean is of type 'com.sun.proxy.$Proxy250' and implements:

()

    com.xinwei.learning.mapper.StudentMapper

Expected a bean of type 'com.xinwei.learning.manager.education.mapper.TeachingClassStudentMapper' which implements:

    com.xinwei.common.db.mapper.BaseMapperX

Action:

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.

 

报错原因:

是因为我们用了注解@Resource 注入接口或者映射文件,然后多个地方注入后的别名不一致,就会出现这个问题。

解决办法:

1. 每个注入接口或者映射文件的地方,统一取同一个别名,如下:

classStudentMapper
    @Resource    private TeachingClassStudentMapper classStudentMapper;

2.或者运用@Autowired注解注入即可,每个类注入后的别名可以不一样

    @Autowired    private TeachingClassStudentMapper classStudentMapper;

上一篇:电脑怎么更换服务器地址?

下一篇:服务器怎么改流量图?