【发布时间】:2013-12-04 18:14:21
【问题描述】:
似乎我通过谷歌从各种来源搜索信息以解决我的问题,但我仍然遇到麻烦。 为了澄清我的问题,我会尽可能多地为您提供信息。
我正在使用 NetBeans IDE 7.3.1 和 Spring 3.1.1。
我现在拥有的:
我创建了 6 个类和 1 个 xml 文件。
这些课程运行良好(因为这些课程基于我目前正在阅读的书)。
我想我的 jar 文件有问题(可能版本兼容性有问题或其他问题(idk,我是这个范围内的新手))。
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
**http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">**
<bean id="knight" class="castle.BraveKnight">
<constructor-arg ref = "quest"/>
</bean>
<bean id="quest"
class="castle.SlayedDragonQuest"/>
<bean id="mistreal"
class="castle.Mistreal"/>
<aop:config>
<aop:aspect ref="mistreal">
<aop:pointcut id="embark"
expression="execution(* *.embarkQuest(..))" />
<aop:before pointcut-ref="embark"
method="singBeforeQuest"/>
<aop:after pointcut-ref="embark"
method="signAfterQuest"/>
</aop:aspect>
</aop:config>
</beans>
编译我的代码后,我得到了这个:
线程“main”中的异常 org.springframework.beans.factory.BeanDefinitionStoreException:从类路径资源 [knight.xml] 解析 XML 文档时出现意外异常;嵌套异常是 java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
很明显,classloader 找不到我的名为 Advice 的 aop 类。但是为什么呢?
我像这样在我的项目中添加了 jars:
我错过了什么吗?谁能给我一些信息。 (我阅读了相关资源,但结果是一样的)。
谢谢
已编辑:
我添加了 aopalliance.jar 文件,现在我得到了这个:
线程“main”中的异常 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [knight.xml] 中定义的名称为“knight”的 bean 时出错:bean 实例化之前的 BeanPostProcessor 失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#1' 的 bean 时出错:无法创建 [org.springframework.aop 类型的内部 bean '(inner bean)' .aspectj.AspectJAfterAdvice] 设置构造函数参数时;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“(内部 bean)#2”的 bean 时出错:无法创建类型为 [org.springframework.aop.config.MethodLocatingFactoryBean] 的内部 bean“(内部 bean)”在设置构造函数参数时;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“(内部 bean)#2”的 bean 时出错:bean 初始化失败;嵌套异常是 java.lang.IllegalArgumentException:无法在 bean [mistreal] 上找到方法 [signAfterQuest] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452) 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
似乎一种解决方案会引发另一个问题。我该如何解决? 附:我没有使用 Marven。这也是我图片中的一个错误,我在我的项目中修复了它,但它没有改变任何东西。
Mistreal 类:
package castle;
public class Mistreal {
public void singBeforeQuest(){
System.out.println("Singing before quest");
}
public void singAfterQuest(){
System.out.println("Singing after quest");
}
}
【问题讨论】:
-
不要关注 SPRING-AOP jar 文件中的 2 个不同版本(我删除了我的 3.0.7),所以现在我的项目中只添加了 3.0.0 版本。结果是一样的。
-
向我们展示您的
Mistreal课程。 -
你只是打错了,见下文。