value for the annotation attribute must be constant expression

后端 未结 2 1508
囚心锁ツ
囚心锁ツ 2021-01-19 17:27

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

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

after I get th

相关标签:
2条回答
  • 2021-01-19 17:35

    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;
    
    0 讨论(0)
  • 2021-01-19 17:54

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

    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.

    0 讨论(0)
提交回复
热议问题