1. 程式人生 > >security中jsr250不生效解決辦法

security中jsr250不生效解決辦法

在springSecurity.xml檔案中開啟註解支援,springSecurity中預設是關閉的:
<security:global-method-security jsr250-annotations=“enabled”/>
在pom檔案中新增依賴:

javax.annotation
jsr250-api
1.0

然後在方法上使用註解的過程中@RolesAllowed({“ROLE_ADMIN”})註解不起作用,許可權不受控制,有登陸許可權的人都可以訪問任意資源。
解決方法:將@RolesAllowed({“ROLE_ADMIN”})從controller層移到service層,問題就得到解決。
具體原因:沒想清楚。歡迎補充,解釋