javaasyncresttemplate

get external url from application.properties with pathvariable


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?


Solution

  • 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:

    and store the value

    I hope I helped