注记属性值必须是常量前pression [英] value for the annotation attribute must be constant expression

查看:410
本文介绍了注记属性值必须是常量前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性文件,我读过春季注释这样

I have a properties file that I read by spring annotation like this

    @Value("${platform}")
    private String platform;

后,我拿到的平台参数,我想这取决于平台参数值。

    @Value("${url." + platform + ."ws}")
    private String url;

但是这给了错误,为注释属性值必须是常量前pression。
因为有很多的参数变化取决于平台的价值,我要寻找一个通用的解决方案。

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.

推荐答案

该参数在编译时间进行评估。因此,它需要最后静态最后等等(即枚举)。

The parameter is evaluated in compilation time. So it needs to be final or static final among others (ie Enum).

我不知道,如果 @Value 注释允许的。但你总是可以实现自己的注释。扩展是不可能在Java注解。

I don't know if the @Value annotation allows that. But you can always implement your own annotation. Extending is not possible in Java annotations.

这篇关于注记属性值必须是常量前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆