Tuesday, September 25, 2012

Spring - java.lang.ClassNotFoundException: org.aopalliance.aop.Advice

Even after adding all Spring 3.1 jar i was getting excpetion as below :

Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException:
Caused by: java.lang.ClassNotFoundException: org.aopalliance.aop.Advice
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 49 more
   
Solution :

As part of https://jira.springsource.org/browse/SPR-2011, Removed AOP Alliance interfaces from spring-aop.jar and
the aopalliance.jar needs to be added explicitly. Instead of using jar from any other sources, it's better to use jar from official maven repository.


Goto Central repository http://search.maven.org/#browse and search for org.aopalliance.aop.Advice in advance search by class name.
After adding aopalliance-1.0.jar, issues is resolved. And i am able to use MethodBeforeAdvice in terface. 

Author : Anuj Patel
Blog : http://goldenpackagebyanuj.blogspot.in/