springboot Autowired BeanNotOfRequiredTypeException
现象
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'xxxxImpl' is expected to be of type 'com.xxx.xxxImpl' but was actually of type 'com.sun.proxy.$Proxy62'
直接Autowired一个实现类,而不是接口
@Autowired private XxxServiceImpl xxxService;
解决方案
1. Autowired接口
2. 使用EnableAspectJAutoProxy
SpringBootApplication @EnableAspectJAutoProxy(proxyTargetClass = true) public class Application {public static void main(String[] args) {SpringApplication app = new SpringApplication(Application.class);app.run(args);} }
设置proxy-target-class为true即使用cglib的方式代理对象,默认是jdk方式代理。
jdk的动态代理不支持类注入,只支持接口方式注入。
动态代理类型判断
//org.springframework.aop.framework.DefaultAopProxyFactory //参数AdvisedSupport 是Spring AOP配置相关类 public AopProxy createAopProxy(AdvisedSupport advisedSupport) throws AopConfigException { //在此判断使用JDK动态代理还是CGLIB代理 if (advisedSupport.isOptimize() || advisedSupport.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(advisedSupport)) { if (!cglibAvailable) { throw new AopConfigException( "Cannot proxy target class because CGLIB2 is not available. " + "Add CGLIB to the class path or specify proxy interfaces."); } return CglibProxyFactory.createCglibProxy(advisedSupport); } else { return new JdkDynamicAopProxy(advisedSupport); } }
转载于:https://www.cnblogs.com/hujunzheng/p/8428422.html
springboot Autowired BeanNotOfRequiredTypeException相关推荐
- 一次SpringBoot AutoWired 注入服务为null的事件
问题表述: java.lang.NullPointerExceptionat com.ynd.back.socket.WebSocket.onMessage(WebSocket.java:113)at ...
- 2021年22月3日
springboot @Autowired注解 错误变为警告 Mybatis注解 <dependency><groupId>junit</groupId><a ...
- SpringBoot集成Quartz(解决@Autowired空指针Null问题即依赖注入的属性为null)
SpringBoot集成Quartz(解决@Autowired空指针Null问题即依赖注入的属性为null) 参考文章: (1)SpringBoot集成Quartz(解决@Autowired空指针Nu ...
- 关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...
错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...
- autowired 静态方法使用_关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...
错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...
- spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误
spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...
- SpringBoot 中@Autowired 注入失效原因及解决方法
SpringBoot 中@Autowired 注入失效原因及解决方法 1.原因分析 1.1 包没有被扫描到通过@Autowired注入的类所在的包路径不在Application启动类所在的包/子包路径 ...
- SpringBoot学习——@Autowired自动注入报:could not be found问题的理解和解决方案
微服务应用程序中,我们会通过Java后台的方式发送http请求并调用其他注册在Spring Cloud Eureka server上的微服务,之前我们可能会手动封装一个Http发送请求类,然后通过其中 ...
- 【SpringBoot】拦截器使用@Autowired注入接口为null解决方法
[SpringBoot]拦截器使用@Autowired注入接口为null解决方法 参考文章: (1)[SpringBoot]拦截器使用@Autowired注入接口为null解决方法 (2)https: ...
最新文章
- 深度学习--感知机讲解
- 强人工智能是潘多拉魔盒吗
- 一款 0 门槛轻松易上手的数据可视化工具
- 大讲堂 | 预测时间敏感的机器学习模型建模与优化
- 程序员——[小鸟语录]
- oracle删除资产模块凭证,请教老师,固定资产凭证不小心给删除了,然后在固定资产模块那边说已经存在了,那我要怎么做?...
- Hadoop学习记录(6)|Eclipse安装Hadoop 插件
- 4.11 UIDatePicker日期时间选择器 [原创iOS开发-Xcode教程]
- 2021年计算机能力挑战赛真题总结C++版
- Windows7安装无法识别硬盘分区
- 三次方程求根公式例子
- python少儿趣味编程多少钱一节_学费昂贵的少儿编程课,为什么被追捧?
- Matplotlib 箱线图
- 双软企业认定的好处有哪些
- 【商业信息】PNP ID注册名单 2019-05-21
- SCANV团队预警libsys图书馆系统注入漏洞
- 普通高中计算机装备标准,福建省普通高中信息技术装备标准.doc
- python123填充颜色_WPS表格中如何设置图案填充颜色透明度?,值得收藏
- 产品经理修炼需要注意的七个点
- 计算机三级数据库技术知识点
热门文章
- adb echo shell 覆盖_一次写shell脚本的经历记录
- 苹果电脑上使用linux环境变量,mac系统下修改环境变量
- install python 3.5.0_Mac 下安装Python3.5出现“python3-3.5.0 already installed, it's just not linked”错误...
- CentOS7 最小化安装工具包精简版本
- VM安装CentOS6.8虚拟机
- 企业实战(Jenkins+GitLab+SonarQube)_12_Jenkins+soanr服务器搭建和代码检查
- JavaScript-Iterable迭代
- 邮件格式转换html,HTML邮件模板 - lenglingx的个人页面 - OSCHINA - 中文开源技术交流社区...
- mysql5.7是测试版本吗_mysql免安装版本测试(mysql-5.7.18-winx64)
- java+多线程菜鸟_java多线程