在Spring注释中使用静态变量 [英] Using static variables in Spring annotations

查看:563
本文介绍了在Spring注释中使用静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using spring's PreAuthorize annotation as follows:

@PreAuthorize("hasRole('role')");

但是,我已经在另一个类上将角色"定义为静态字符串.如果我尝试使用此值:

However, I already have 'role' defined as a static String on another class. If I try to use this value:

@PreAuthorize("hasRole(OtherClass.ROLE)");

我得到一个错误:

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'

是否可以通过PreAuthorize批注来访问像这样的静态变量?

Is there a way to access static variables like this with a PreAuthorize annotation?

推荐答案

尝试以下使用Spring Expression Language评估类型的方法:

Try the following which uses Spring Expression Language to evaluate the type:

@PreAuthorize("hasRole(T(fully.qualified.OtherClass).ROLE)");

请确保指定完全合格的类名称.

Be sure to specify the fully qualified class name.

文档

这篇关于在Spring注释中使用静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆