Problem solving bean types in spring configuration: beannotofrequiredtypeexception
The reason for this problem is that it is common to inject spring beans in a way that uses annotation, specifically because of the mechanism that spring uses for proxy, see the code used:
Java code
1. Use class injection:
@Resource (name = "Aisleservice")
Private Aisleservice Aisleservice;
2. Using interface injection:
@Resource (name = "Aisleservice")
Private Iaisleservice Aisleservice;
Code 1 cannot use the dynamic agent injection of the JDK because the dynamic agent of the JDK does not support class injection, only the interface mode injection is supported;
Code 2 can use JDK dynamic agent injection;
If you want to use code 1, you must use the Cglib proxy;
Of course, the recommended way to use code 2, based on the interface programming way!
About the configuration of the spring dynamic agent:
1. Use the AOP configuration:
<aop:config proxy-target-class= "false" > </aop:config>
2. ASPECTJ Configuration:
<aop:aspectj-autoproxy proxy-target-class= "true"/>
3. Transaction annotation Configuration:
<tx:annotation-driven transaction-manager= "TransactionManager" proxy-target-class= "true"/>
3 configurations, as long as you use one, set Proxy-target-class to True to use the Cglib proxy object
Troubleshooting bean Types in spring configuration: beannotofrequiredtypeexception