Spring needs to set proxy-target-class= "true" when using AOP otherwise it cannot rely on injection

Source: Internet
Author: User

When using Spring's dependency injection (annotations or XML) and AOP features in Spring3 or later versions, an issue was found if <aop:aspectj-autoproxy proxy-target-class= "true" is not set > always reported when fetching beans: (no beans can be obtained either by name or by type)

Org.springframework.beans.factory.NoSuchBeanDefinitionException:No Unique Bean of type

Or
Java.lang.ClassCastException:com.sun.proxy. $Proxy cannot is cast to Cn.edu.nuc.SpringTest.service.impl.DemoServiceImpl


Proxy-target-class= "True" differs from proxy-target-class= "false":
The Proxy-target-class property value determines whether an interface-based or class-based proxy is created. If the Proxy-target-class property value is set to True, then the class-based proxy will function (this requires the Cglib library). If the Proxy-target-class value is set to False or if this attribute is omitted, then the standard JDK interface-based proxy


Reference: http://forum.spring.io/forum/spring-projects/data/58033- Beannotofrequiredtypeexception-using-servicelocatorfactorybean-and-transactional

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Spring needs to set proxy-target-class= "true" when using AOP otherwise it cannot rely on injection

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.