首页 文章

Spring xml问题

提问于
浏览
6

我正在尝试编写一个简单的Spring AOP应用程序,但我遇到了xml配置问题 .

我的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">

<bean id="audience" class="springaop.Audience">
</bean>

<bean id="sam" class="springaop.Singer">
    <property name="id" value="1"></property>
</bean>

<aop:config>
    <aop:aspect ref="audience">

        <aop:before pointcut="* springaop.Singer.perform(..)" 
        method="takeSeats"></aop:before>

    </aop:aspect>
</aop:config>

</beans>

我得到这个警告和例外:

WARNING: Ignored XML validation warning
    org.xml.sax.SAXParseException: SchemaLocation: schemaLocation value = 'http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/aop' must have even number of URI's.

Exception: Line 18 in XML document from class path resource [aop-conf.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:config'.

另外,我无法理解xmlns

2 回答

  • 6

    将XML顶部的 <beans 声明更改为如下所示:

    <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">
    

    你只是添加了这个"http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" . xsi:schemaLocation 属性只是一堆对 . 每对中的第一个是模式URI,第二个是可以找到模式的URL . 您可以将其视为 Map :键,然后是值 .

  • 17

    xsi:schemaLocation 属性必须具有偶数个URI . 每对将名称空间URI与XSD的位置相关联 . 您的 xsi:schemaLocation 包含三个URI,因此无效 . 这就是消息告诉你的内容 .

    你需要为 http://www.springframework.org/schema/aop 提供XSD的位置

相关问题