AngularJS Load Properties File Servlet Implementation
Recently we were working on project where client had been written using AngularJS framework and it was getting dynamic data from many RESTFul service which was hosted on multiple server. Requirement was to replace service URL value dynamically on different environment. Based on requirement we had created separate environment properties file and load/read/replace its values based on server environment. In this tutorial you will see how to load environment properties file and replace values on AngularJS page:
- Create Maven project: LoadPropertiesFileAngularJS.
As you see above project structure we have created properties file for all environment. We will do servlet based implementation to load and read property value. For AngularJS servlet will work as service and it will make call to the the servlet to get environment specific URL and replace on AngularJS page.
- AngularJS index.html page:
- We will run this project on Tomcat 7, If you are not sure how to configure and run tomcat inside eclipse please use this tutorial. Start tomcat server and here you will see output of URL which we are reading from properties file. For this demo our environment is QA so it will print QA URL:
- If you want learn AngularJS please read their official tutorial here