Shiro @RequiresRoles注解不起作用的解决办法
2018-03-08 13:53
2351 查看
最近在学习SSM框架下集成Shiro,在使用Shiro注解的使用发现并不起作用,并且也在applicationContext.xml中添加了Shiro开启注解的配置。
Shiro 开启注解的配置如下:
经过一番搜索,发现了问题所在,我是在controller中使用的Shiro注解,而且我的开启注解的配置写在了Spring的配置文件下,而我的Spring配置自动扫描的时候,过滤掉使用了Controller注解的类,如下所示:
所以解决办法也很简单,将开启Shiro注解的配置写到SpringMVC的配置文件里即可。
Shiro 开启注解的配置如下:
<!--Shiro配置--> <!-- 1.配置lifecycleBeanPostProcessor,可以在Spring IOC容器中调用shiro的生命周期方法. --> <bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor" id="lifecycleBeanPostProcessor" /> <!-- 2.启用Spring IOC容器Shiro注解,但必须配置了lifecycleBeanPostProcessor后才可以使用 --> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor" /> <!-- 3.开启Spring AOC Shiro注解支持 --> <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> <property name="securityManager" ref="securityManager"/> </bean>
经过一番搜索,发现了问题所在,我是在controller中使用的Shiro注解,而且我的开启注解的配置写在了Spring的配置文件下,而我的Spring配置自动扫描的时候,过滤掉使用了Controller注解的类,如下所示:
<!--自动扫描--> <context:component-scan base-package="com.dream" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
所以解决办法也很简单,将开启Shiro注解的配置写到SpringMVC的配置文件里即可。
相关文章推荐
- Shiro的注解(@RequiresRoles,@RequiresPermissions)授权不起作用
- Spring的Aop授权不起作用,例如Shiro的注解(@RequiresRoles,@RequiresPermissions)
- Shiro的注解(@RequiresRoles,@RequiresPermissions)授权不起作用
- shiro注解不起作用的解决办法---实测保证药到病除
- Shiro @RequiresRoles注解不生效解决方案及相应设置
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- Mybatis整合Spring3,事务注解为何不起作用的解决办法
- apache shiro框架的@RequiresRoles 不起作用
- Shiro与Spring集成时,Shiro权限注解@RequiresRoles等不生效的解决方案
- shiro 注解授权不起作用问题解决方案
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- shiro添加注解@RequiresPermissions不起作用
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- Shiro注解@RequiresPermissions不起作用
- shiro与spring整合详解与spring项目中shiro注解不生效的解决办法
- 使用Spring配置shiro时,自定义Realm中属性无法使用注解注入解决办法
- shiro添加注解@RequiresPermissions不起作用
- shiro添加注解@RequiresPermissions不起作用
- 解决:BeanNotOfRequiredTypeException办法 @Autowired和@Resource注解的不同