Spring表达式求值(注释)
我有以下问题: 我想使用Spring将属性“password”引用的值传播到类变量:Spring表达式求值(注释),spring,annotations,Spring,Annotations,我有以下问题: 我想使用Spring将属性“password”引用的值传播到类变量: @Value("${password}") private String password; 只要spring能够找到名为“password”的属性,这种方法就可以工作。因为它不会为所有不同的执行定义,所以我希望能够在passwort属性不可用时指定一个默认值 我发现了以下示例: @Value("${size_count?:5}") private int count; 这很有效。但是,当我对pas
@Value("${password}")
private String password;
只要spring能够找到名为“password”的属性,这种方法就可以工作。因为它不会为所有不同的执行定义,所以我希望能够在passwort属性不可用时指定一个默认值
我发现了以下示例:
@Value("${size_count?:5}")
private int count;
这很有效。但是,当我对password(type String)尝试相同的方法时,它的计算结果将始终为false,并返回字符串“x”,尽管password属性已经定义
@Value("${password?:x}")
private String password;
有什么想法吗
干杯
克里斯试试看(我猜,不确定是否有意义)
?:
用于Spring表达式语言,即{…}
在属性占位符(${…}
)中,需要使用:
:
@Value("${password:x}")
private String password;
这正是我所建议的+为此,不管是对是错:-)谢谢。我也想到了这个主意。如果密码是'bla',那么表达式的结果将是:bla?:'x',因此表达式必须在{}之内。:)哈哈。。。你觉得怎么样?@chr1s-我得问问。人们通常会假设一些他们没有尝试过的东西。再加上“wolud”这个词:)就够了。我真的试过了!这就是结果。“will”字已与if语句结合使用:)+1表示:因为这是属性占位符配置器的正确synax
@Value("${password:x}")
private String password;