![](/img/trans.png)
[英]Getting a error in Spring Configuration XML file:org.xml.sax.SAXParseException
[英]I am getting error in Spring Configuration XML file:org.xml.sax.SAXParseException
我正在使用AOP,但我一直無法解決此錯誤。 我的Spring Configuration 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>
出現錯誤的行位於控制台中,如下所示。
線程“主”中的異常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:類路徑資源[beans.xml]中XML文檔中的第21行無效; 嵌套的異常是org.xml.sax.SAXParseException; lineNumber:21; columnNumber:9; 元素類型“ aop:aspect”之后必須是屬性規范“>”或“ />”。
看來aop:pointcut有兩個同名的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標記,並希望這可以解決您的問題。
請進行更改,然后回復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.