app+rbac:No bean resolver registered in the context to resolve access to bean 'rbacService'
来源:7-4 基于数据库Rbac数据模型控制权限
j2tech
2018-01-30
复现步骤:(底部附解决方案)
git clone讲师源码
更改test依赖(特殊说明:为browser依赖时正常)

3. 成功启动项目,访问请求报错核心:
(1) java.lang.IllegalArgumentException: Failed to evaluate expression '#oauth2.throwOnError(@rbacService.hasPermission(request, authentication))'
(2)Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1057E: No bean resolver registered in the context to resolve access to bean 'rbacService'
========================================================================
解决方案:
使用demo工程也是一样的,最终源码里可能重构后动了版本,
我找到了是oauth的bug(详见:https://github.com/spring-projects/spring-security-oauth/issues/730#issuecomment-219480394),
可在源码ImoocResourceServerConfig类中加入以下代码即可解决:
@Bean
public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
expressionHandler.setApplicationContext(applicationContext);
return expressionHandler;
}
@Autowired
private OAuth2WebSecurityExpressionHandler expressionHandler;
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.expressionHandler(expressionHandler);
}
4回答
-
飘香随云
2018-09-18
你好,为啥我用这段后,authentication里面的认证信息变成匿名访问账户了,。
112019-03-03 -
beyond_0012
2018-05-15
困扰了好久的问题,谢谢
00 -
丽濡
2018-01-31
非常感谢
00 -
JoJo
2018-01-31
额...代码就是为Browser写的,不是为app写的,因为WebExpressionVoter只有在web环境中才会配置。
052018-01-31
Spring Security技术栈开发企业级认证与授权
2662 学习 · 1561 问题
相似问题