Chris S
Chris S

Reputation: 3

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.

Upvotes: 0

Views: 734

Answers (2)

Chris S
Chris S

Reputation: 3

Thanks Max for your quick help! With your inputs I have implemented below steps in WebSphere to keep the applictaion.properties files in classpath scope and it is working.

  1. Created new Shared library in WebSphere. Envinronment > Shared library > Create New shared library > updated the classpath value with properties file location. (Ex. opt/IBM/MyFolder/config/properties/myapp/) and save the changes.

  2. Update the Spring boot application with shared library. Applications > Application Types > WebSphere enterprise applications > myapp > References > Shared library reference > select application > Reference shared libraries > then add the shared library which was created in 1step.

That's it. Now myapp is reading application.properties file from given shared library path And I removed @PropertySource with absolute path on Springboot application java file. Now I am able to switch the profile without packaging and installing the application.

Upvotes: 0

lane.maxwell
lane.maxwell

Reputation: 5872

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:

  • A /config subdir of the current directory.
  • The current directory
  • A classpath /config package
  • The classpath root

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.

Upvotes: 0

Related Questions