java - 我在 Spring 配置 XML 文件 :org. xml.sax.SAXParseException 中收到错误

标签 java spring spring-aop

我正在使用 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>

我收到错误的行位于我的控制台中,如下所示。

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document from class path resource [beans.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 9; Element type "aop:aspect" must be followed by either attribute specifications, ">" or "/>".`

最佳答案

aop:pointcut 似乎有两个同名的 id。

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

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

请重命名 id 并检查。

关于java - 我在 Spring 配置 XML 文件 :org. xml.sax.SAXParseException 中收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30309771/

相关文章:

java - Spring AOP : Declaring additional methods or fields on behalf of a type

java - 如何将 JSONObject 转换为带有字符串变量的 Java Bean?

java - java中将一串位转换为unicode字符

Java - 如何在多个类中使用同一个对象

java - 从 Web 应用程序访问静态文件(webapp/static/例如)

java - 从 catch block 中调用 @afterThrowing 建议打印抛出的异常

java - @ControllerAdvice,如何获取调用该方法的类?

java - 如何将用户以 MM-dd-yyyy 格式选择的日期转换为 Java 中的 yyyy-MM-dd 格式

java - Netflix Feign : Response Body empty in ErrorDecoder on 404

java - 参数调用中的大括号。 >> 这是什么意思? | Spring 3 和 GWT