Wednesday, October 1, 2014

How to dynamically replace Hard coded values Programatically

This blog explains about how to eliminate hard coded URL's in any web application. Especially hard coding the environment specific WSDL URL's or any other string values.

- Create a properties file and define all the values as  key value pair. Key must contains host name.

For eg : dev340 is the host name
              dev340_EMPWSDL =dev340:9080/emp/EmployeeManage?WSDL





- Wherever you want to retrieve the values from the properties file dynamically where the application is running
// Below code gives the host name where the application is running.
String hostName = java.net.InetAddress.getLocalHost().getHostName();

For eg : If the application is running in DEV environment, hostName value will be obtained as 'dev340' ,


- You need to retrieve property value from .properties file by passing hostname, Follow below blog to how to read properties file

http://fortunefusionminds.blogspot.com/2014/02/how-to-read-properties-file-in-java.html

No comments:

Post a Comment