admin管理员组

文章数量:1530077

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