Spring aop java.lang.NoClassDefFoundError

7

我有一个aop配置问题。这是我的Spring XML配置的一部分:

<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>

这是我的主方法:

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();
    }

}

当我运行它时,我收到了NoClassDefFoundError异常。
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

无法确定问题所在。希望能得到帮助。


可能是重复的问题:新手使用Spring - STS中缺少AOP库,求助! - Raedwald
1个回答

14

这个问题:Missing Spring AOP libraries in STS 似乎涉及到了一个类似的问题(缺少库),还有这个Spring 论坛帖子也是一个这样的问题。

你的classpath中是否包含了提到的jar文件?

<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>

3
谢谢,添加这些依赖项有所帮助。 cglib cglib 2.2 org.aspectj aspectjweaver 1.6.11 (请注意,原文已经是英文) - pomkine
2
为什么我们需要这些依赖项?它们不是为了AspectJ吗?我遇到了同样的问题,但我不使用AspectJ,我想使用Spring AOP。 - Erlan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接