4

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}") ?

6
  • You can use SpEL. Commented Dec 7, 2021 at 6:22
  • @BoristheSpider can you please show example? Commented Dec 7, 2021 at 6:23
  • try #{${prop.a} + ${prop.b}} Commented Dec 7, 2021 at 6:28
  • getting this error paste.ubuntu.com/p/p9vSDGWWcF Commented Dec 7, 2021 at 6:45
  • 1
    Is it not OK for you if you do this in application.properties itself? Like prop.b=${prop.a}B? Commented Dec 7, 2021 at 6:57

1 Answer 1

9

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.*.)

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry prob was a typo, question updated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.