注释属性的值必须是常量表达式 [英] value for the annotation attribute must be constant expression
本文介绍了注释属性的值必须是常量表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个属性文件,我通过这样的 spring 注释读取
I have a properties file that I read by spring annotation like this
@Value("${platform}")
private String platform;
获得平台参数后,我想根据platform
参数值读取第二个参数.
after I get the platform parameter, I would like to read a second parameter depending on platform
parameter value.
@Value("${url." + platform + ."ws}")
private String url;
但这会产生错误,注释属性的值必须是常量表达式".由于根据平台"值有很多参数更改,因此我正在寻找通用解决方案.
but this gives error, "value for the annotation attribute must be constant expression". since there are lots of parameter changes depending on "platform" value, I am looking for a generic solution.
推荐答案
您不能直接在 @Value 表达式中访问 platform
,但您可以使用 Spring 表达式语言来实现您的最终目标.
You can't access platform
directly in the @Value expression, but you can use Spring Expression Language to accomplish your end goal.
@Value("${platform}")
private String platform;
@Value("#{'Url.'.concat(${platform}).concat('.ws')}")
private String url;
这篇关于注释属性的值必须是常量表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文