Spring aop java.lang.NoClassDefFoundError

18,227

This question: Missing Spring AOP libraries in STS seems to address a similar problem (missing libraries), also a problem in this Spring Forum thread.

Do you have the mentioned jars on your classpath?

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2</version>
</dependency>
<dependency>  
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.6.11</version>
</dependency>
Share:
18,227
pomkine
Author by

pomkine

Updated on June 04, 2022

Comments

  • pomkine
    pomkine almost 2 years

    I have a problem with aop config. Here is part of my spring xml config:

    <bean id="conLogger" class="com.pomkine.pXMPP.connection_service.ConnectionLogger"/>
    
    <aop:config>
        <aop:aspect ref="conLogger">
            <aop:pointcut id="connect"
                          expression= "execution(* com.pomkine.pXMPP.connection_service.connectionManager.connect(..))" />
            <aop:after pointcut-ref="connect"
                       method="connected"/>
        </aop:aspect>
    </aop:config>
    

    Here is my main method:

    public static void main (String [] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("com/pomkine/pXMPP/connection_service/connection-manager.xml");
        connectionManager cm=(connectionManager)ac.getBean("connectionManager");
        try {
            cm.connect();
            cm.disconnect();
          } catch (XMPPException e) {
            e.printStackTrace();
        }
    
    }
    

    When I'm runnig it I'm getting NoClassDefFoundError exception.

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connect': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
    

    Can't figure out what the problem is. Would appreciate any help.

  • pomkine
    pomkine over 11 years
    Thanks, adding this dependencies helped <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.11</version> </dependency>
  • Erlan
    Erlan almost 9 years
    Why do we need these dependencies? Aren't they for AspectJ? I'm having the same problem but I don't use AspectJ, I want to use Spring AOP.