Spring Security无法注入authenticationManager

2019-12-05 18:55:16 浏览数 (1)

Description: Field authenticationManager in xxx.auth.config.MyAuthorizationConfig required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found. Action: Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.

注入申明

代码语言:javascript复制
@Autowired
private AuthenticationManager authenticationManager;

解决方案

在WebSecurityConfigurerAdapter的实现类当中,重写authenticationManagerBean方法:

代码语言:javascript复制
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
}

0 人点赞