spring security 注解和配置文件

想必大家和我一样都卡在了 @RolesAllowed 注解 没有相对应的效果 ,这个问题也是硬生生卡了我两天 ,最终还是如愿的解决了, 下面就和大家来分享我的解决方案

 

 

1.首先就是看自己的 applicationContext配置文件 中有没有加上 开启springsecurity注解,这里 小编 也是踩过一个坑 把这个配置写到了spring-security当中 ,然后我对应的注解是写在

controller 中,问题就是出在这里 ,我的spring-security不是去管理我的controller层注解,所以把如下配置加到了applicationContext当中,我们的applicationContext 也是去注入我们 service 

层 ,所以正好也把我们的@RolesAllowed 注解写在 applicationContext中

 

 

    <security:global-method-security
            secured-annotations="enabled"
            pre-post-annotations="enabled"
            jsr250-annotations="enabled"/>

 

 

 

 

2.service 层 @RolesAllowed注解 给方法或者类给予权限

 

 

posted @ 2021-03-09 15:09  Kc_blog  阅读(239)  评论(0编辑  收藏  举报