2016-10-02 40 views
0

我得到的錯誤與Spring配置:無效的含量被發現開始元素「認證經理

Invalid content was found starting with element 'authentication-manager'. 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"]}' is expected. 

這裏是bean的XML文件:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="com.rsc."/> 
    <mvc:annotation-driven /> 

    <authentication-manager alias="authenticationManager"> 
     <authentication-provider user-service-ref="userDetailsServiceImpl"> 
      <password-encoder ref="encoder"></password-encoder> 
     </authentication-provider> 
    </authentication-manager> 

    <bean id="userDetailsServiceImpl" class="com.rsc.service.UserDetailsServiceImpl"></bean> 

    <bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"> 
     <constructor-arg name="strength" value="11"/> 
    </bean> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/views/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 
</beans> 

我添加了所有所需的豆配置,但仍然出現錯誤。我在配置中缺少什麼?

回答

1

我想你需要添加spring security namespace。

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    [...] 

    <security:authentication-manager> 
     ... 
    </security:authentication-manager> 

    [...] 

</beans> 

因爲beans是默認的命名空間春天試圖找到authentication-manager那裏。因此您需要引入security命名空間。請參閱文檔以獲取更多信息:http://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#d0e507

+0

我已經知道了,但是感謝您的正確答案 – Satyadev

+0

很棒的@Satyadev。別客氣! –

相關問題