解析xsd架构时出现Spring错误

时间:2015-06-19 10:38:22

标签: java xml spring xsd

我正在尝试使用Spring Security模块,但是我收到有关安全xsd文件的XML Validation错误。

这是spring-security.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">



    <!--  Security....................................... -->

    <security:http security="none" pattern="/resources/**"/>
    <security:http auto-config="true" use-expressions="true" >
        <security:intercept-url pattern="/admin/**" access="hasRole('Admin')" />
        <security:logout logout-success-url="/welcome" logout-url="/logout" />
        <security:form-login login-page="/login"
            default-target-url="/welcome"
            username-parameter="username"
            password-parameter="hashPwd" 
            authentication-failure-url="/login?error"
            />
    </security:http>


    <security:authentication-manager>
       <security:authentication-provider user-service-ref="controlloUtente">
         <security:password-encoder hash="bcrypt" />  
      </security:authentication-provider>
    </security:authentication-manager>

</beans:beans>

这是我得到的例外(我明显检查过,文件存在!):

19/06/2015 12:32:38 - WARN  - (SimpleSaxErrorHandler.java:48) - Ignored XML validation warning
org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 58; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/security/spring-security.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:99)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:433)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:347)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4166)

我落后于代理,但我配置了它,其他的xsd得到了解决,所以我不知道发生了什么。

1 个答案:

答案 0 :(得分:0)

也许这段代码会有所帮助:

<?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:security="http://www.springframework.org/schema/security"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/security
  http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<security:http auto-config="true">

    <security:intercept-url pattern="/login.do"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <security:intercept-url pattern="/logout.do"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <security:intercept-url pattern="/fail2login.do"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <security:intercept-url pattern="/json/*.do"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <security:intercept-url pattern="/*" access="ROLE_ADMIN" />
    <security:form-login login-page="/login.do"
        default-target-url="/home.do" authentication-failure-url="/fail2login.do" />

    <security:session-management>
        <security:concurrency-control
            max-sessions="1" />
    </security:session-management>
    <security:logout logout-success-url="/logout.do"
        delete-cookies="JSESSIONID" invalidate-session="true" />
</security:http>

<security:authentication-manager>
    <security:authentication-provider>
        <security:jdbc-user-service
            data-source-ref="dataSource"
            users-by-username-query="select userName, password, status from User where userName=?"
            authorities-by-username-query="select us.userName, ur.userRoleName from User us, UserRole ur   
            where ur.userName =?  " />
    </security:authentication-provider>
</security:authentication-manager>