相关疑难解决方法(0)

在Spring注释中使用静态变量

我正在使用spring的PreAuthorize注释如下:

@PreAuthorize("hasRole('role')");
Run Code Online (Sandbox Code Playgroud)

但是,我已经将'role'定义为另一个类上的静态String.如果我尝试使用此值:

@PreAuthorize("hasRole(OtherClass.ROLE)");
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 14): Field or property 'OtherClass' cannot be found on object of type 'org.springframework.security.access.expression.method.MethodSecurityExpressionRoot'
Run Code Online (Sandbox Code Playgroud)

有没有办法使用PreAuthorize注释访问这样的静态变量?

java spring spring-security spring-annotations

16
推荐指数
5
解决办法
1万
查看次数