I have a situation were i need to call an external endpoint. I am using spring boot. I have placed the endpoint in the application.properties
file and used a placeholder for the parameter I need to change like so: messageapi=http://localhost:8080/uxt/get/{{userId}}/messages/notification
where userid is a dynamic value generated in code.
what is the most efficient way for me to to access this value in asyncRestTemplate.exchange() method and replace the variable?
This how i would approach it. I would plase a string placeholder, get it with @Value and then I would use String.format. So here it goes:
Step 1 use this format in your application.properties
file entry messageapi=http://localhost:8080/uxt/get/%s/messages/notification
Step 2 in your class use the
@Value("${messageapi}")
String messageapi;
and store the value
Step 3 use the following to replace the userId String.format(messageapi,"userId "));
and in your case somthing like
asycTemp.exchange(String.format(messageapi,"userId ")), method, requestEntity, responseType);
I hope I helped