0

How can my Spring Boot application read application.properties values with a parameter(s) like it's possible for ResourceBundles using MessageFormat?

For instance, if I have in application.properties:

crm.api.url.contact=/contacts/v1/contact/vid/{0}/profile

What's the best way to replace thee placeholder {0} with a real value (an ID in this case)?

du-it
  • 2,561
  • 8
  • 42
  • 80

1 Answers1

0

If there is no better way, I solved my problem using MessageFormat in conjunction with @Value:

// Autowired via constructor based injection
private final String MY_API_KEY;
private final String MY_API_URL_BASE;
private final String MY_API_URL_CONTACT;

MessageFormat.format(MY_API_URL_BASE + MY_API_URL_CONTACT + MY_API_URL_API_KEY_PARAM + MY_API_KEY, contactId.toString()), String.class);
du-it
  • 2,561
  • 8
  • 42
  • 80