JUnit hint failed to load ApplicationContext in spring

Source: Internet
Author: User

Error tip : 1:java.lang.illegalstateexception:failed to load ApplicationContext

2:error creating Bean with Name ' UserService ' defined in class path resource [Userservice.xml]: initialization of Bean FAI Led Nested exception is Org.springframework.aop.framework.AopConfigException:Cannot proxy target class because CGLIB2 are not Available. Add CGLIB to the class path or specify proxy interfaces.

3:cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

root cause : The root cause is a missing cglib package because the Web has an error while loading the spring configuration file (Applicationcontext.xml), and the error is 3 (cglib2 unavailable).

the proxy configuration in Applicationcontext.xml is as follows :

<!--specify to use Cglib--
<aop:aspectj-autoproxy proxy-target-class= "true"/>

<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "*"/>
</tx:attributes>
</tx:advice>
<!--provides transactional enhancements through AOP configuration, allowing all methods of all beans under the service package to have transactions--
<aop:config proxy-target-class= "true" >
<aop:pointcut id= "Servicemethod" expression= "Execution (* com.luxl.service). *(..))" />
<aop:advisor pointcut-ref= "Servicemethod" advice-ref= "Txadvice"/>
</aop:config>

Workaround: Add the Cglib package to maven as follows:

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>

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.