springboot+shiro中使用 @RequiresPermissions和@RequiresRoles無效的解決方法
阿新 • • 發佈:2018-12-26
最近在使用shiro框架的時候,出現了@RequiresPermissions和@RequiresRoles無效的情況,經過查閱大佬的部落格,記錄一下解決方法。
在ShiroConfig中加入一下程式碼即可。
/** * 開啟shiro aop註解支援. * 使用代理方式;所以需要開啟程式碼支援; * @param securityManager * @return */ @Bean public LifecycleBeanPostProcessor lifecycleBeanPostProcessor(){ return new LifecycleBeanPostProcessor(); } @Bean @DependsOn({"lifecycleBeanPostProcessor"}) public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){ DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); advisorAutoProxyCreator.setProxyTargetClass(true); return advisorAutoProxyCreator; } @Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){ AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); return authorizationAttributeSourceAdvisor; }