我有一个 Eclipse-Maven-Spring 项目和一个applicationcontext.xml
。这是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<description>SoapClient1</description>
<context:component-scan base-package="hu.bz.ikti.soap.test"/>
...
</beans>
解析xml时出现以下错误:
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 19 in XML document from class path resource [META-INF/spring/app-context1.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 'context:component-scan'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
在后面的<http>
xml元素的开头有一个错误标志:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http://
www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias,
"http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/
schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected.
在我试图添加的xsi:schemaLocation
部分中
http://www.springframework.org/schema/context/spring-context-3.2.xsd, spring-context-3.1.xsd, spring-context.xsd
但我总是遇到同样的错误。
我的pom.xml
中有以下内容:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
有人可以帮助我吗?
答案 0 :(得分:3)
xsi:schemaLocation
不仅仅是一个模式列表,它是一个名称空间URI的对列表及其对应的模式位置。所以你需要更像
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">