admin管理员组文章数量:1410780
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.
2023-09-22 17:02:30.288 ERROR 14476 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'menuServiceImpl' could not be injected as a 'com.pjp.system.service.Impl.MenuServiceImpl' because it is a JDK dynamic proxy that implements:
com.pjp.system.service.MenuService
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.
出现错误的原因:
这个错误通常是由于在Spring应用程序中,尝试注入一个接口而不是具体的实现类。当使用@Resource注解或Autowired注解时,Spring默认会将所注入的bean转换为其具体实现类的实例。但是,如果存在多个实现类,则可能会出现注入错误。
可以通过以下方式解决这个问题
方式1:
在application.properties 配置信息里面加入
spring.aop.proxy-target-class=true
方式2:
在配置类上加上 以下两个注解
@EnableCaching(proxyTargetClass = true) //开启支持缓存的注解 并基于类进行代理
@EnableAsync(proxyTargetClass = true) //开启对异步任务的支持
本人使用方式2得到解决
本文标签: Beaninterfaceserrorinjectingbased
版权声明:本文标题:[ERROR]Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxie 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1738333087a2076409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论