2012-12-28 32 views
10

Possible Duplicate:
Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘springSecurityFilterChain’ is defined無豆命名的AuthenticationManager

在我的Spring應用程序,我不斷收到此錯誤:

No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a gobal <authentication-manager> element to your configuration (with child <authentication-provider> elements)? Alternatively you can use the authentication-manager-ref attribute on your <http> and <global-method-security> elements. 

在我的春季安全方面的XML文件,我已經定義如下:

<beans:bean id="myUserDetailsService" class="com.myProject.core.security.MyUserDetailsService" /> 

<beans:bean id="encoder" class="com.myProject.core.security.HmacPasswordEncoder" /> 

<authentication-manager id="clientAuthenticationManager" > 
    <authentication-provider user-service-ref="myUserDetailsService"> 
     <password-encoder ref="encoder" /> 
    </authentication-provider> 
</authentication-manager> 

當我明確定義了我的身份驗證管理器和身份驗證提供程序時,爲什麼會抱怨?

注:這可能幫助,它是一個更具描述性的錯誤:

org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'org.springframework.security.filterChains': Cannot resolve reference to bean 
'org.springframework.security.web.DefaultSecurityFilterChain#2' while setting bean 
property 'sourceList' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': 
Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' 
while setting constructor argument with key [1]; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': 
Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' 
while setting bean property 'authenticationManager'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve 
reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' 
while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': 
FactoryBean threw exception on object creation; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 
'org.springframework.security.authenticationManager' is defined: Did you forget to 
add a gobal <authentication-manager> element to your configuration (with child 
<authentication-provider> elements)? Alternatively you can use the authentication-manager-ref 
attribute on your <http> and <global-method-security> elements. 

回答

13

的AuthenticationManager會被擡起頭來名稱,所以只需將其更改爲以下內容:

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

這沒有爲我工作。 – user1007895

+0

或甚至<認證管理器> <認證提供源用戶服務-REF = 「myUserDetailsS​​ervice」> <密碼編碼器REF = 「編碼器」/> iMysak

+0

從第二個建議中刪除'id =「clientAuthenticationManager」',看看是否可行 - 查看更新的編輯。 –

1

看看這個鏈接:

Notice that the filter is actually a DelegatingFilterProxy, and not the class that will actually implement the logic of the filter. What DelegatingFilterProxy does is delegate the Filter's methods through to a bean which is obtained from the Spring application context.

...

You need to define a bean named springSecurityFilterChain that implements javax.servlet.Filter in your application context.

+0

你能顯示一些代碼嗎? – user1007895

2

您需要更改您的Spring Security Context文件以查找clientAuthenticationManager。您可以添加此行到您的http設置

<http use-expressions="true" authentication-manager-ref="clientAuthenticationManger"> 
+0

是的,它試圖通過「authenticationManager」的名稱獲得認證管理器引用,所以填寫你的認證管理器參考。 –

相關問題