Spring Security 3.1 xsd 和 jars 不匹配问题

Posted

技术标签:

【中文标题】Spring Security 3.1 xsd 和 jars 不匹配问题【英文标题】:Spring Security 3.1 xsd and jars mismatch issue 【发布时间】:2012-10-01 07:15:58 【问题描述】:

我正在尝试从 spring 框架 3.0.5 迁移到 3.1 和 spring-security 3.0.5 到 3.1(更不用说 hibernate 3.6 到 4.1)。使用 Apache IVY。

我在尝试在 Eclipse Helios 中启动 Tomcat 7.23 时遇到以下错误(在许多其他人中,但这是控制台中的最后一个):

org.springframework.beans.factory.BeanDefinitionStoreException: Line 7 in XML document from ServletContext resource [/WEB-INF/focus-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans:beans", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "beans:beans", must match DOCTYPE root "null".

我的安全配置文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">

Ivy.xml 看起来像这样:

<dependencies>
<dependency org="org.hibernate" name="hibernate-core" rev="4.1.7.Final"/>
<dependency org="org.hibernate" name="com.springsource.org.hibernate.validator" rev="4.2.0.Final" />
<dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.0-api" rev="1.0.1.Final"/>
<dependency org="org.hibernate" name="hibernate-entitymanager" rev="4.1.7.Final"/>
<dependency org="org.hibernate" name="hibernate-validator" rev="4.3.0.Final"/>

<dependency org="org.springframework" name="spring-context" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework" name="spring-web" rev="3.1.2.RELEASE"/>   
<dependency org="org.springframework" name="spring-tx" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework" name="spring-webmvc" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework" name="spring-test" rev="3.1.2.RELEASE"/>

<dependency org="org.springframework.security" name="spring-security-core" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework.security" name="spring-security-web" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework.security" name="spring-security-config" rev="3.1.2.RELEASE"/>
<dependency org="org.springframework.security" name="spring-security-taglibs" rev="3.1.2.RELEASE"/>

<dependency org="net.sf.dozer" name="dozer" rev="5.3.2"/>
<dependency org="org.apache.poi" name="poi" rev="3.8"/>
<dependency org="commons-io" name="commons-io" rev="2.4"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6"/>
<dependency org="org.slf4j" name="slf4j-ext" rev="1.6.6"/>
<dependency org="log4j" name="log4j" rev="1.2.17"/>
<dependency org="org.testng" name="testng" rev="6.8"/>
<dependency org="org.dbunit" name="dbunit" rev="2.4.8"/>
<dependency org="org.easymock" name="easymock" rev="3.1"/>
</dependencies>

我了解(希望)此错误是由于声明的 xsd 与类路径上的 jar 不匹配造成的。任何指针将不胜感激。

【问题讨论】:

【参考方案1】:

试试这个模式位置:xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" 这也将指向最新的模式。同时删除您在tomcat中的工作文件夹以确保没有冲突..

【讨论】:

以上是关于Spring Security 3.1 xsd 和 jars 不匹配问题的主要内容,如果未能解决你的问题,请参考以下文章

spring 3.1 with hibernate 4 with spring security 3.1:如何确保包含所有依赖项以及要包含哪些标签?

Spring Security 3.1:Active Directory 身份验证和本地 DB 授权

Spring Security 3.1 + JPA - 空指针异常

spring security 3.1 isAuthenticated() 不工作

Spring security 3.1如何处理不同的认证异常?

如何在 Spring Security 3.1 中进行没有身份验证和授权的并发会话控制