spring cloud 问题记录(十三)authenticationManager无法注入问题

在配置spring cloud security的过程中出现如下异常信息导致无法启动项目

Field authenticationManager in com.clark.online.edu.config.AuthorizationServerConfig 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.

看错误信息就很明白了,就是需要authenticationManager,但是没有在config里面注入,但是实际上在我的config配置里面已经注入了,代码如下:

	/**
	 * 认证管理
	 */
	@Autowired
	private AuthenticationManager authenticationManager;
	/**
	 * redis连接工具
	 */
	@Autowired
	private RedisConnectionFactory redisConnectionFactory;
	
	/**
	 * redis存储token
	 * @return
	 */
	@Bean
	RedisTokenStore redisTokenStore() {
		return new RedisTokenStore(redisConnectionFactory);
	}
	
	/**
	 * 配置
	 */
	@Override 
	public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
		endpoints.tokenStore(redisTokenStore()).authenticationManager(authenticationManager);
	}

其实原因我不知道,解决方法很简单就是重新实例化bean就OK

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
	/**
	 * 重新实例化bean
	 */
	@Override
	@Bean
	public AuthenticationManager authenticationManagerBean() throws Exception {
		return super.authenticationManagerBean();
	}
}

 

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值