Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot how to append multiple properties to single value?

I have multiple properties in my application.properties file

prop.a=A
prop.b=B
prop.c=C
// and more

Now i have to add the property A to the rest of them. I am doing this like following

    @Value("${prop.a}")
    private String a;

    @Value("${prop.b}")
    private String b;
    b = new StringBuffer(b).append(a).toString();

I have to individually append each string. Can i do this in the annotation? like @Value("${prop.b}" + "${prop.a}") ?

like image 973
mahfuj asif Avatar asked Sep 16 '25 22:09

mahfuj asif


1 Answers

If you want to do this programmatically, you have to do this:

@Value( "${prop.a}${prop.b}" )
private String b;

You can, however, achieve this in application.properties itself this way:

prop.a=A
prop.b=${prop.a}B
prop.c=${prop.a}C

(Please note that wherever your example says prob.*,I have changed to prop.*.)

like image 60
Sree Kumar Avatar answered Sep 19 '25 14:09

Sree Kumar