Java – use static variables in spring annotations
•
Java
I am using spring's preauthorize annotation as follows:
@PreAuthorize("hasRole('role')");
However, I have defined 'role' as a static string of another class If I try to use this value:
@PreAuthorize("hasRole(OtherClass.ROLE)");
I received an error:
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'
Is there any way to use preauthorize annotation to access such static variables?
Solution
Try using the following spring expression language to evaluate types:
@PreAuthorize("hasRole(T(fully.qualified.OtherClass).ROLE)");
Be sure to specify a fully qualified class name
Documentation
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码