Open pengliangs opened 6 years ago
Spring 2.x 好像不能注入了, 解决方案:
在WebSecurityConfigurerAdapter的实现类当中,重写authenticationManagerBean方法:
@Bean(name = BeanIds.AUTHENTICATION_MANAGER) @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } 但是会导致安全配置都失效~~~ 提示:{"timestamp":1546938283602,"status":401,"error":"Unauthorized","message":"Unauthorized","path":"/oauth/token"}%
问题解决了: @Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* Spring 2.0 不会自动注入这个实例了
* @return
* @throws Exception
*/
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
也可以构造器注入
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter{
/**
* 构造函数注入
*/
private AuthenticationManager authenticationManager;
/**
* 注入AuthenticationManager
* @param authenticationConfiguration
* @throws Exception
*/
public AuthorizationServerConfig(AuthenticationConfiguration authenticationConfiguration) throws Exception {
this.authenticationManager = authenticationConfiguration.getAuthenticationManager();
}
@Autowired private AuthenticationManager authenticationManager;