2013-06-25 99 views
0

我收到此錯誤,當我添加篩選器鏈代理bean。我想我必須創建一個名爲securityContextPersistenceFilterWithASCTrue的bean,但在示例中沒有顯示這樣的bean。有沒有解決方法?春季安全自定義篩選器初始化

SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'filterChainProxy' defined in ServletContext resource [/WEB-INF/spring-security.xml]:  Cannot resolve reference to bean 'securityContextPersistenceFilterWithASCTrue' while  setting bean property 'filterChainMap' with key [Root bean: class  [org.springframework.security.web.util.AnyRequestMatcher]; scope=; abstract=false;  lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false;  factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]  with key [0]; nested exception is  org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named  'securityContextPersistenceFilterWithASCTrue' is defined 

這是我的Spring配置;

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



<http auto-config='true' use-expressions="true"> 
    <intercept-url pattern="/login" access="permitAll"/> 
    <intercept-url pattern="/ajaxErrorPage" access="permitAll"/> 
    <intercept-url pattern="/pages/*" access="hasRole('admin')" /> 
    <intercept-url pattern="/j_spring_security_check" access="permitAll"/>   
    <logout logout-success-url="/login.xhtml" /> 
    <form-login login-page="/login.xhtml" 
       login-processing-url="/j_spring_security_check"              
       default-target-url="/pages/index.xhtml" 
       always-use-default-target="true"               
       authentication-failure-url="/login.xhtml"/> 
</http> 


<!--Authentication Manager Details -->  
<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="customUserDetailsService"> 
     <!--   <password-encoder hash="md5"/>--> 
    </authentication-provider> 
</authentication-manager> 


<beans:bean id="filterChainProxy" 
    class="org.springframework.security.web.FilterChainProxy"> 
<filter-chain-map>  
<filter-chain pattern="/**" filters=" 
     securityContextPersistenceFilterWithASCTrue, 
     formLoginFilter, 
     exceptionTranslationFilter, 
     filterSecurityInterceptor, 
     customAjaxControlFilter" /> 
</filter-chain-map> 
</beans:bean> 


</beans:beans> 

回答

0

當使用命名空間配置(<http auto-config ...>),根據您的安全命名空間(等)配置的內容會自動創建過濾器鏈代理。否則,如果要顯式定義filter-chain-proxy,則必須將名稱空間配置放在一邊,並配置每個bean spring安全性將自動爲您創建(如果使用該命名空間配置)。

在你的情況,我想你可以刪除「filterChainProxy」bean配置,保持你爲表單登錄做的配置。