简体   繁体   English

我在Spring Configuration XML文件中遇到错误:org.xml.sax.SAXParseException

[英]I am getting error in Spring Configuration XML file:org.xml.sax.SAXParseException

I am using AOP and I am stuck with this error I can't fix. 我正在使用AOP,但我一直无法解决此错误。 My Spring Configuration XML file is: 我的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>

The Line I am getting error is in my console as shown below. 出现错误的行位于控制台中,如下所示。

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document from class path resource [beans.xml] is invalid; 线程“主”中的异常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:类路径资源[beans.xml]中XML文档中的第21行无效; nested exception is org.xml.sax.SAXParseException; 嵌套的异常是org.xml.sax.SAXParseException; lineNumber: 21; lineNumber:21; columnNumber: 9; columnNumber:9; Element type "aop:aspect" must be followed by either attribute specifications, ">" or "/>".` 元素类型“ aop:aspect”之后必须是属性规范“>”或“ />”。

It seems there are two id's with same name for aop:pointcut. 看来aop:pointcut有两个同名的ID。

<aop:pointcut id="pc1" expression="execution(public int com.aamir.Person.*(int, ..))"/>

<aop:pointcut id="pc1" expression="execution(* com.aamir.*.*(..))"/>

rename id and check plz. 重命名id并检查plz。

Is this the complete XML file that you have provided above ? 这是您上面提供的完整XML文件吗?

In case this is true, then you need to add closing beans tag in the end of xml file and hopefully that should take care of your problem. 如果是这样,那么您需要在xml文件的末尾添加闭合bean标记,并希望这可以解决您的问题。

Please make the change and reply back. 请进行更改,然后回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM