从Spring Security Expressions调用静态方法? [英] Calling static methods from Spring Security Expressions?
问题描述
我正在寻找一种扩展Spring Security Expressions以支持现有安全基础结构的方法.我知道您可以按照引用以通过Spring表达式语言(Spring EL或SpEL)直接调用静态方法.不幸的是,关于Spring Expression方法的官方页面并没有不能直接描述如何做到这一点.
I'm looking for a way to extend Spring Security Expressions to support an existing security infrastructure. I'm aware you can extend the MethodSecurityExpressionRoot as described here, but I also found reference to directly calling static methods through Spring Expression Language (Spring EL or SpEL). Unfortunately the official page on Spring Expression methods doesn't directly describe how to do this.
如何通过Spring Expression方法调用静态方法?
How can I invoke a static method through Spring Expression methods?
推荐答案
By using the T(fully.qualified.name).methodName()
syntax:
您可以使用特殊的
T
运算符来指定java.lang.Class
的实例(类型).静态方法也可以使用此运算符来调用.StandardEvaluationContext
使用TypeLocator
查找类型,并且StandardTypeLocator
(可以替换)是在理解java.lang
包的基础上构建的.这意味着T()
对java.lang
中的类型的引用不需要完全限定,但是所有其他类型的引用都必须是完全限定的.
You can use the special
T
operator to specify an instance ofjava.lang.Class
(the type). Static methods are invoked by using this operator as well. TheStandardEvaluationContext
uses aTypeLocator
to find types, and theStandardTypeLocator
(which can be replaced) is built with an understanding of thejava.lang
package. This means thatT()
references to types withinjava.lang
do not need to be fully qualified, but all other type references must be.
T
元素返回对该类型的引用,而不是实例.例如,Collections.singleton("Hello")
的等效项是
The T
element returns a reference to the type instead of an instance. For example, the equivalent of Collections.singleton("Hello")
is
T(java.util.Collections).singleton('Hello')
这篇关于从Spring Security Expressions调用静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!