Java Spring表达式语言-在注释中获取系统属性

Java Spring表达式语言-在注释中获取系统属性,java,spring,spring-mvc,Java,Spring,Spring Mvc,在我的控制器中,我试图在Spring注释中获取系统属性。这是密码 @PreAuthorize(“hasPermission('${systemProperties['user.name']}','') 这将抛出org.springframework.expression.spel.SpelParseException。 我试过了 但会导致相同的异常 在Spring批注中获取系统属性的语法是什么?请尝试以下操作: @Component public class WhateverBean {

在我的控制器中,我试图在Spring注释中获取系统属性。这是密码

@PreAuthorize(“hasPermission('${systemProperties['user.name']}','')

这将抛出
org.springframework.expression.spel.SpelParseException
。 我试过了

但会导致相同的
异常

在Spring批注中获取系统属性的语法是什么?

请尝试以下操作:

@Component
public class WhateverBean {

    @Value("#{systemProperties['user.name']}")
    private String userName;

    public String getUserName() {
        return userName;
    }

    @PreAuthorize("hasPermission('@whateverBean.getUserName()', '')")
    public void xxx() {
        // ...
    }
}

您是否应该使用
#{systemProperties
而不是
${systemProperties
exception@Suganthan尝试给出的例子,让我知道。在本地它是有效的,否则我会删除答案,如果这是不正确的。
@Component
public class WhateverBean {

    @Value("#{systemProperties['user.name']}")
    private String userName;

    public String getUserName() {
        return userName;
    }

    @PreAuthorize("hasPermission('@whateverBean.getUserName()', '')")
    public void xxx() {
        // ...
    }
}