Problem solving bean types in spring configuration: beannotofrequiredtypeexception

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.