Java 类的SpEL引用实例变量

Java 类的SpEL引用实例变量,java,spring,spring-boot,spring-security,spring-el,Java,Spring,Spring Boot,Spring Security,Spring El,我正在为我的spring security预授权注释使用一个自定义方法,我需要传入一长串perm。我想在外部存储该列表,因为它在一些地方使用,但我似乎不知道如何引用该列表。它似乎总是以空的形式出现 @RestController @RequestMapping("/example") public class MyController { ...constructor/other stuff public List<String> perms_I_want_to_referenc

我正在为我的spring security预授权注释使用一个自定义方法,我需要传入一长串perm。我想在外部存储该列表,因为它在一些地方使用,但我似乎不知道如何引用该列表。它似乎总是以空的形式出现

@RestController
@RequestMapping("/example")
public class MyController  {

...constructor/other stuff
public List<String> perms_I_want_to_reference = Arrays.asList("super","long","list")

@PreAuthorizze("@securityService.MyCustomMethod(principal, *this where I want to reference perms*)
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<?>doSomethingTopSecret(){
}

}
@RestController
@请求映射(“/示例”)
公共类MyController{
…构造函数/其他东西
公共列表perms\u I\u want\u to\u reference=Arrays.asList(“super”、“long”、“List”)
@预授权(@securityService.MyCustomMethod(主体,*此处我要引用perms*))
@RequestMapping(method=RequestMethod.GET)
公共响应TENTITYDOSOMETHINGTOPSECRET(){
}
}

我尝试过#并使用
T
使列表保持静态,但到目前为止一切都不起作用。

从注释访问字段的唯一方法是通过反射。为了做到这一点,Spring需要访问该类的字段。我还没有听说过在表达式为正在进行评估,但一种方法是引用bean本身并访问字段:

public List<String> perms_I_want_to_reference = Arrays.asList("super","long","list");

@PreAuthorizze("@securityService.MyCustomMethod(principal, @myController.perms_I_want_to_reference)")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<?>doSomethingTopSecret(){ }
public List perms_I_want_to_reference=Arrays.asList(“super”、“long”、“List”);
@预授权(@securityService.MyCustomMethod(主体,@myController.perms\u I\u want\u to\u reference)”)
@RequestMapping(method=RequestMethod.GET)
公共响应EntityDosoMethingTopSecret(){}

你需要什么来传递它们?你不能直接从securityService.MyCustomMethod访问它们吗?所以很多控制器使用该服务,而它不知道是谁在调用它。没错,我想我可以重构,以某种方式知道或接收关于谁在调用的反馈。我通过使perms列表为静态并使用t实现了这一点,但我不会这样做如果有人知道if/how/whynot我不能做我想做的事情,请打电话给我,这样我发现我可以使用
t
和完整的包名并访问类的静态属性,但最终得到了类似于您的解决方案,我使用另一个bean加载常量,因为我觉得它读起来最好。完全限定的包和变量名对我来说是冗长的。