Reputation: 3
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.
@PropertySource({"file: /opt/config/application.properties"}
Application.properties
file has only spring.profiles.active-dev
I placed application-dev.properties file in the same path but spring boot app is not able to read the dev file. it just able to read application.property file which is given in @PropertySource.
My requirement is:application.properties
application-dev.properties
application-qa.properties
application-prod.properties
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
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.
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.
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
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:
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