如何解决 java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27324015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice error?
提问by tadpole
I am trying to use the spring AOP framework. The code compiled without error. When I tried to run it, I got the above exception. I am using netbeans IDE 8.0.1. I have the following libraries and jar files included.
我正在尝试使用 spring AOP 框架。代码编译没有错误。当我尝试运行它时,出现上述异常。我使用的是 netbeans IDE 8.0.1。我包含以下库和 jar 文件。
1) Spring Framework 4.0.1
2) aspectjrt.jar
3) aspectjweaver.jar
4) aopalliance-alpha1.jar
5) asm-5.03.jar
6) cglib-3.1.jar
Here is my spring.xml config file
这是我的 spring.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
">
<aop:aspectj-autoproxy/>
<bean name="triangle" class="springaop.Triangle">
<property name="name" value="My Triangle" />
</bean>
<bean name="circle" class="springaop.Circle">
<property name="name" value="My Circle" />
</bean>
<bean name="shapeService" class="springaop.ShapeService" autowire="byName" >
</bean>
<bean name="loginAspect" class="springaop.LoginAspect" />
</beans>
These are the latest jar files that are available from each publisher. I did not see the Advice class anywhere in the aopalliance jar. I searched for this problem. It appears that the Advice class may have been removed from the aopalliance jar. I have not been able to search it. Does anyone know how to resolve this problem other than telling me to use Maven :) ?
这些是每个发布者提供的最新 jar 文件。我在 aopalliance jar 的任何地方都没有看到 Advice 类。我搜索了这个问题。似乎 Advice 类可能已从 aopalliance jar 中删除。我一直无法搜索它。除了告诉我使用 Maven 之外,有没有人知道如何解决这个问题:)?
回答by Sotirios Delimanolis
回答by Nupur
I had the same error as I had added aopalliance-alpha1.jar instead of aopalliance.jar. I added the correct jar and it started working .
我有同样的错误,因为我添加了 aopalliance-alpha1.jar 而不是 aopalliance.jar。我添加了正确的 jar 并开始工作。
回答by N N Prasad
I also got the same error in my eclipse env.
我的 eclipse env 也遇到了同样的错误。
Cause : For working on spring aop examples, from the net I downloaded the files 'aopalliance-.jar.zip', 'aspectj-1.6.9.jar.zip', 'aspectjrt.jar.zip', 'aspectj-weaver.jar.zip' and included it directly in the java build path. The mistake I did here was I didn't extract the jar files from the zip file, instead directly added the .jar.zip file into the java build path.
原因:为了处理 spring aop 示例,我从网上下载了文件“aopalliance-.jar.zip”、“aspectj-1.6.9.jar.zip”、“aspectjrt.jar.zip”、“aspectj-weaver”。 jar.zip' 并将其直接包含在 java 构建路径中。我在这里犯的错误是我没有从 zip 文件中提取 jar 文件,而是直接将 .jar.zip 文件添加到 java 构建路径中。
Fix : Extract the jar files from above mentioned .jar.zip files and in the eclipse point to the jar files instead of zip files, then it will start working.
修复:从上面提到的 .jar.zip 文件中提取 jar 文件,并在 eclipse 中指向 jar 文件而不是 zip 文件,然后它将开始工作。