Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies 问题解决

编程知识 更新时间:2023-05-02 05:23:50

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.

问题描述

Spring Boot 项目,启用事务支持时出现以下错误:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with ‘debug’ enabled.

2018-12-28 09:19:09.467 ERROR 1105 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

The bean ‘departmentDao’ could not be injected as a ‘com.wanyu.fams.dao.DepartmentDao’ because it is a JDK dynamic proxy that implements:

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.

也就是添加了一个注解:@Transactional // 启用事务处理,启动的时候就报错了。

解决方法
在 application.properties 或者 application.yml 配置文件中添加配置:

以下为 application.properties 中的配置方法:

解决问题


spring.aop.proxy-target-class=true

application.yml 写法有点不同:

spring:
  aop:
    proxy-target-class: true

失败的尝试

有文章指出:在springboot启动类中添加如下代码,最终解决问题,我尝试失败,错误依旧!

@Bean
    @ConditionalOnMissingBean
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
        daap.setProxyTargetClass(true);
        return daap;
    }

更多推荐

Consider injecting the bean as one of its interfaces or forcing the use of CGLib

本文发布于:2023-04-26 05:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/7e7fa298d4720b03cd96e0e82bf279fc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:interfaces   bean   injecting   forcing   proxies

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104359文章数
  • 26212阅读数
  • 0评论数