我正在尝试编写一个简单的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
答案 0 :(得分:18)
将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。您可以将其视为地图:键,然后是值。
答案 1 :(得分:6)
xsi:schemaLocation
属性必须包含偶数个URI。每对将名称空间URI与XSD的位置相关联。您的xsi:schemaLocation
包含三个URI,因此无效。这就是消息告诉你的内容。
您需要提供http://www.springframework.org/schema/aop