I have a properties file that I read by spring annotation like this
@Value("${platform}")
private String 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.
A constant expression is an expression that always produces the same result. More precisely, a constant expression is an expression that produces a pure value of a primitive data type and is only composed of the following: Literals of primitive data types. String literals.
We can also explicitly specify the attributes in a @Test annotation. Test attributes are the test specific, and they are specified at the right next to the @Test annotation.
if the compiler expects an "Array Initializer" to be passed to the Annotation, declaring a compile-time constant like private static final String[] AB = { ... }; should do. it's understood that Annotation processing happens before the actual compilation, but then the error message is not accurate.
Java Custom annotations or Java User-defined annotations are easy to create and use. The @interface element is used to declare an annotation. For example: @interface MyAnnotation{}
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With