Spring Security:autowire ProviderManager [英] Spring Security: autowire ProviderManager
问题描述
我试图使用Spring Security以编程方式验证用户登录/传递,因此我需要访问 ProviderManager
。我希望它被自动注入到 @Controller
中。
我的代码如下所示:
import org.springframework.security.authentication.ProviderManager;
// ...
@Controller
public class MyController {
$ b $ @Autowired
私有ProviderManager authenticationManager;
但是,当我尝试运行应用程序时,出现以下错误消息:
没有定义[org.springframework.security.authentication.ProviderManager]类型的唯一bean:
期望单个匹配的bean,但找到2:
[org.springframework.security.authentication.ProviderManager#0,org.springframework.security.authenticationManager]
<
我在Spring 3.0.1中使用Spring Security 3.0.0-RC1,而且我还没有解决这个问题。定义了任何 ProviderManager
bean。我成功地使用过:
@Resource
private ProviderManager authenticationManager;
在其他项目中,但 javax.annotation.Resource $ c $有两个
AuthenticationManager
不支持GAE。
-
org.springframework.security.authenticationManager
填充< authentication-manager>
-
org.springframework.security.authentication.ProviderManager中显式声明的身份验证提供程序#0
填充隐式声明的提供程序(记住我,匿名等),并将身份验证请求委托给org.springframework.security.authenticationManager
作为后备。
所以,我想你需要
@Autowired @Qualifier(org.springframework.security.authenticationManager)
I am trying to programatically validate a user login/pass using Spring Security, so I need to have access to the ProviderManager
. I would like it to be automatically injected into my @Controller
.
My code looks like:
import org.springframework.security.authentication.ProviderManager;
// ...
@Controller
public class MyController {
@Autowired
private ProviderManager authenticationManager;
But when I try to run the application I get this error message:
No unique bean of type [org.springframework.security.authentication.ProviderManager] is defined:
expected single matching bean but found 2:
[org.springframework.security.authentication.ProviderManager#0, org.springframework.security.authenticationManager]
What could be the cause or how could I solve it?
I am using Spring Security 3.0.0-RC1 with Spring 3.0.1, and I've not defined any ProviderManager
bean. I've successfully used:
@Resource
private ProviderManager authenticationManager;
in other projects, but javax.annotation.Resource
is not supported in GAE.
There are two AuthenticationManager
s in the context:
org.springframework.security.authenticationManager
is populated with authentication providers explicitly declared in<authentication-manager>
org.springframework.security.authentication.ProviderManager#0
is populated with implicitly declared providers (remember me, anonymous and so on) and delegates the authentication request toorg.springframework.security.authenticationManager
as a fallback.
So, I guess you need
@Autowired @Qualifier("org.springframework.security.authenticationManager")
这篇关于Spring Security:autowire ProviderManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!