Spring XML问题 [英] Spring xml problem
问题描述
我正在尝试编写一个简单的Spring AOP应用程序,但是xml配置存在问题.
I'm trying to write a simple Spring AOP app, but I have problem with the xml 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-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
Also, I cant understand the xmlns
推荐答案
更改XML顶部的<beans
声明,如下所示:
Change the <beans
declaration at the top of the XML to look like this:
<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.您可以将其视为一个映射:键,然后是值.
You're just adding this "http://www.springframework.org/schema/aop/spring-aop-3.0.xsd". The xsi:schemaLocation
attribute is just a bunch of pairs. The first of each pair is a schema URI, the second is the URL where the schema can be found. You can think of it as a map: key, then value.
这篇关于Spring XML问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!