Spring: nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

后端 未结 6 1395
栀梦
栀梦 2020-12-31 13:03

Stack trace:

Oct 24, 2014 8:12:04 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.         


        
相关标签:
6条回答
  • 2020-12-31 13:11

    Along with aopalliance jar have you added these jars into your build path??

    aspectjrt
    springaop
    aspectjweaver

    If not, you can try by adding these..

    P.S: use the appropriate version of jars...

    0 讨论(0)
  • 2020-12-31 13:17

    cross check with com.springsource.org.aopalliance-X.X.X.jar

    0 讨论(0)
  • 2020-12-31 13:17

    I removed SPRING-LIBRARY completely and then added all the required jars one by one plus cglib-nodep-2.2.jar.
    There was also a spelling mistake in my code <bean id="quest" class="com.java.spring.ResqueDamselQuest" />

    public class RescueDamselQuest implements Quest {
    

    Name of class.

    But I am sure this spelling mistake was not the reason for the exception I was getting. After adding the jars from scratch I got this error that said the bean is not found as mentioned in the knights-aop.xml sth.. sth... which is when I figured that I have this typo.

    This is how my jars are added now:

    enter image description here

    I hope someone might get help from this answer.

    ###########EDIT###########

    asm-all & cglib-nodep are not required. Also, some jar from spring download was causing problems, as I tried adding all the jars I got in spring download and it started showing the old exception again. So it is better to add jar as and when required.

    0 讨论(0)
  • 2020-12-31 13:20

    It looks like you only add the aopalliance jar to the build classpath of your IDE (Eclipse ?). That explains that the IDE shows no error and accepts to build the application. But in fact, you must also add it to the run classpath.

    Depending on the IDE you use, another menu may allow to configure it. But if you want to run it outside the IDE, you must put the jar in your normal classpath, either by putting it along with other existing jars, or (would be better) by changing you user or system classpath to include the folder that contains the jar.

    I could elaborate on that if you need and if I know your system ...

    0 讨论(0)
  • 2020-12-31 13:22

    You're missing the dependency. Not sure how you're handling dependencies, but just add the JAR in IVY or whatever you use. You must be using something to add Spring 3.2.

    Maven Central: link

    IVY Example: <dependency org="org.springframework" name="spring-aop" rev="3.2.11.RELEASE" /> Maven has other dependency information available.

    If this is a web app, make sure the JAR is in APPNAME/WEB-INF/lib.

    0 讨论(0)
  • 2020-12-31 13:29

    Be totally sure you have the following in your pom.xml file:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    

    According with your error stack trace.

    Caused by: java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

    The following is mandatory

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    

    Of course you must set or configure each version, for Spring and AOP.

    I did realize later you are not working with Maven, even with that in Maven Central Repository you are able to download the jars required according with my dependencies shared above

    0 讨论(0)
提交回复
热议问题