2011-08-04 30 views
5

我正在尝试编写一个简单的Spring AOP应用程序,但我遇到了xml配置问题。Spring 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

回答

16

变化提供XSD的位置在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。您可以将其视为地图:钥匙,然后是价值。

6

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

您需要为http://www.springframework.org/schema/aop