昨天在学习Spring security时发现使用注解的方式会导致拦截失败(10/4)而今天发现问题是因为我的controller层的方法使用了
private
进行修饰导致注解失效,问题如下:
@GetMapping("update")
@Secured({"ROLE_normal","ROLE_admin"})
// @PreAuthorize("hasAnyAuthority(iaenoo)")
private String update() {
return "hello update";
}
}
则会拦截失败
@GetMapping("update")
@Secured({"ROLE_normal","ROLE_admin"})
// @PreAuthorize("hasAnyAuthority(iaenoo)")
public String update() {
return "hello update";
}
}
这样就可以拦截成功