Reputation: 2963
This question might have been asked before as it is quite a common exercise, but I am not sure what to search with.
I have a rest client app hosted on one instance of Tomcat and a rest server hosted on a different tomcat instance on another hostname. This works well, but currently I have the hostname hardcoded in the java classes. How can I parameter-ize the host name inside the rest client so that it allows for a future change without restarting the tomcat on which the rest client is hosted ?
Upvotes: 0
Views: 437
Reputation: 288
You can always pass the host name in arguments during client process startup and then read those arguments using System.getProperty("hostName").
Upvotes: 0
Reputation: 19533
A quite common technique to pass environment variables and even hostname is define a System variable that you could read using java.lang.System.getenv() or java.lang.System.getProperty() if you are using Maven once your application startup read this variable in a static class of constants so the value will be set at the beginning and remain until the end of the application there other techniques that involve, web.xml but to keep it simple this will work. Just add the var to the enviroment and read it.
Upvotes: 1
Reputation: 11832
There are a number of solutions you could employ including (but not limited to):
You could employ a caching mechanism if you don't want to look up the value every time - perhaps once it is read it only expires after a number of seconds/minutes, or after a number of calls.
Upvotes: 1