springspring-profiles

How to read environment specific aplication-<env>.properties using Spring profile in Spring boot app .war with WebSphere server 8.5.5


I deployed my spring boot .war file in WebSphere 8.5.5 server and I have enabled spring profiles in application.properties file to read application specific properties files. But I am not sure how to read the external application.properties files using spring profiles in WebSphere. And spring profile is working when I package the war file with all properties file but I want to place the properties file outside of war.

  1. I want place below 3 files in external path in WebSphere application.properties application-dev.properties application-qa.properties application-prod.properties
  2. I will enable spring profile in application.properties file and spring boot application should able to read the respective environment specific property file.
  3. If I package all 4 properties files in war file then profiling is working but when place them in external path it is unable read them in WebSphere.

As per my knowledge, spring boot app can read external config files outside of spring boot jar from same path. But I am not sure how to read same files from external path in webSphere server. Please help me with sample code snippet and steps to implement spring profile for WebSphere.


Solution

  • You shouldn't have to use the @PropertySource annotation, use the conventions that Spring has set forth and you should be fine. Spring will look for these property files in the following locations:

    You must ensure that when you add the files to WebSphere, they're in one of these locations. The current directory is defined as the CWD of the WebSphere process. The classpath is the defined classpath in WebSphere. If you add the property files to any of these four locations, then Spring will be able to pick them up.