Phenomenon
Org.springframework.beans.factory.BeanNotOfRequiredTypeException:Bean named ' Xxxximpl ' is expected to be of type ' Com.xxx.xxxImpl ' but is actually of type ' com.sun.proxy. $Proxy 62 '
Directly autowired an implementation class, not an interface
@Autowiredprivate Xxxserviceimpl Xxxservice;
Solution Solutions
1. Autowired interface
2. Using Enableaspectjautoproxy
true Publicclass application { publicstaticvoid Main (string[] args) { new springapplication (application. Class); App.run (args);} }
Setting Proxy-target-class to True is the proxy object using Cglib, which by default is the JDK mode proxy.
The JDK's dynamic proxy does not support class injection, only interface-mode injection is supported.
Dynamic Proxy type judgment
//org.springframework.aop.framework.DefaultAopProxyFactory//parameter Advisedsupport is a spring AOP configuration related class Publicaopproxy createaopproxy (advisedsupport advisedsupport)throwsaopconfigexception {//determine whether to use the JDK dynamic agent or the Cglib agent if(Advisedsupport.isoptimize () | |Advisedsupport.isproxytargetclass ()||hasnousersuppliedproxyinterfaces (Advisedsupport)) { if(!cglibavailable) { Throw NewAopconfigexception ("Cannot proxy target class because CGLIB2 is not available." + "Add CGLIB to the class path or specify proxy interfaces."); } returnCglibproxyfactory.createcglibproxy (Advisedsupport); } Else { return NewJdkdynamicaopproxy (Advisedsupport); } }
Springboot autowired beannotofrequiredtypeexception