Spring setting @value from another variable

Viewed 4546

Is it possible to set @Value from another variable

For eg.

System properties : firstvariable=hello ,secondvariable=world

@Value(#{systemProperties['firstvariable'])
String var1;

Now I would like to have var2 to be concatenated with var1 and dependant on it , something like

    @Value( var1 + #{systemProperties['secondvariable']
    String var2;

public void message(){ System.out.printlng("Message : " + var2 );
3 Answers

In my case (using Kotlin and Springboot together), I have to escape "$" character as well. Otherwise Intellij IDEA gives compile time error:

Implementation gives error:

@Value("${SCRIPT_PATH}")
private val SCRIPT_PATH: String = ""

Error: An annotation argument must be a compile-time constant

Solution:

@Value("\${SCRIPT_PATH}")
private val SCRIPT_PATH: String = ""
Related