我正在使用AOP,我遇到了这个无法修复的错误。我的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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="adv1" class="com.aamir.Advice1"/>
<bean id="adv2" class="com.aamir.Advice2"/>
<bean id="p1" class="com.aamir.Person"/>
<bean id="e1" class="com.aamir.Employee"/>
<aop:config>
<aop:aspect id="asp1" ref="adv1">
<aop:pointcut id="pc1" expression="execution(public int com.aamir.Person.*(int, ..))"/>
<aop:before method="executeBeforeMethod" pointcut-ref="pc1"/>
</aop:aspect>
<aop:aspect id="asp2" ref="adv2">
<aop:pointcut id="pc1" expression="execution(* com.aamir.*.*(..))"/>
<aop:pointcut id="pc2" expression="execution(public * com.aamir.Employee.*(..))"/>
<aop:before method="method1" pointcut-ref="pc1"/>
<aop:after method="method2" pointcut-ref="pc1"/>
<aop:after-returning method="method3" returning="obj" pointcut-ref="pc1"/>
<aop:after-throwing method="method4" throwing="e" pointcut-ref="pc1"/>
<aop:before method="method1" pointcut-ref="pc2"/>
</aop:aspect>
</aop:config>
</beans>
我得到错误的行在我的控制台中,如下所示。
线程"main"异常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: XML文档中来自类路径资源[beans.xml]的第21行无效;嵌套异常是org.xml.sax.SAXParseException;lineNumber: 21;columnNumber: 9;元素类型"aop:aspect"必须后跟属性说明">"或"/>"。
似乎aop有两个相同名称的id:切入点。
<aop:pointcut id="pc1" expression="execution(public int com.aamir.Person.*(int, ..))"/>
<aop:pointcut id="pc1" expression="execution(* com.aamir.*.*(..))"/>
重命名id并检查plz
这是您上面提供的完整的XML文件吗?
如果这是真的,那么您需要在xml文件的末尾添加关闭bean标记,希望这应该解决您的问题。
请修改并回复。