2012-04-29 88 views
1

這裏是我的應用程序security.xml文件:錯誤:元素前綴「安全」,「安全性:認證供應商」未綁定

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
    - Sample namespace-based configuration 
    - 
    - $Id: applicationContext-security.xml 3019 2008-05-01 17:51:48Z luke_t $ 
    --> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:beans="http://www.springframework.org/schema/beans" 
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"> 

<global-method-security secured-annotations="enabled"> 
</global-method-security> 

<!-- Don't set any role restrictions on login.jsp --> 
    <intercept-url pattern="/login.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 

    <!-- Restrict access to ALL other pages --> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <intercept-url pattern="/admin/*.html" access="ROLE_ADMIN" /> 
    <intercept-url pattern="/manager/*.html" access="ROLE_MANAGER" /> 
    <intercept-url pattern="/**.html" access="ROLE_USER,ROLE_ADMIN, ROLE_MANAGER" /> 
    <!-- Set the login page and what to do if login fails --> 
    <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1" default-target-url="/user/userdashboard/dashboard.html" /> 
    <logout logout-success-url="/login.jsp"/> 
</http> 

<!-- 
Usernames/Passwords are 
    rod/koala 
    dianne/emu 
    scott/wombat 
    peter/opal 
--> 
    **<security:authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource" /> 
    </security:authentication-provider>** 
</beans:beans> 

一切工作正常,但我得到這個元素「security:authentication-provider」的「前綴」安全性的奇怪錯誤未被綁定。「即使我提供了結束標記。任何人有任何關於如何解決這個問題的線索?

回答

8

既可以使用 「安全」 的所有元素,通過使用proper namespace

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

然後使用 「安全」 隨處可見,比如:

<security:global-method-security secured-annotations="enabled"> 
</security:global-method-security> 

或者完全地擺脫它:

... 
<authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource" /> 
    </authentication-provider> 
... 

因爲您配置了默認命名空間xmlns="http://www.springframework.org/schema/security"