1
votes

We have a websphere application server where multiple applications are deployed. All applications use a common property(Key) but have different Value. For example : spring.profiles.active=test in one application, spring.profiles.active=UAT in some other application. Is it possible to pass these different values to the applications during start-up in Websphere ?

If we set these values in JVM options in the Generic JVM Arguments text box then it will become same for all the applications which we don't want.

Set these properties at application level in websphere so that when applications are started - For application 1 - spring.profiles.active=test For application 2 - spring.profiles.active=UAT

1
Which Websphere version are you usingShailesh Chandra
If they're Java system properties (acquired with System.getProperty), then the answer is "no" - system properties are common to the entire JVM. If there's another mechanism to set them (like a properties file), then the answer should be "yes" but depends a bit on what that mechanism is.Jarid

1 Answers

2
votes

This document indicates that you can set the spring.profiles.active property in a WebApplicationInitializer per web application. Each application could then read its own specifically named property from System properties. Alternatively if using Liberty (the question didn't specify between traditional WebSphere vs Liberty), then you could use MicroProfile Config to define a property with a common name that is defined differently per application via appProperties, for example as shown in this knowledge center article. But you would still need the WebApplicationInitializer to read the value from MicroProfile Config.

An example would be something like the following:

Config config = ConfigProvider.getConfig();
servletContext.setInitParameter(
    "spring.profiles.active",
    config.getValue("ProfilesActive", String.class));

server.xml:

<server>
  <featureManager>
    <feature>mpConfig-1.3</feature>
    .. other features
  </featureManager>

  <application location="app1.war">
    <appProperties>
      <property name="ProfilesActive" value="test"/>
    </appProperties>    
  </application>

  <application location="app2.war">
    <appProperties>
      <property name="ProfilesActive" value="UAT"/>
    </appProperties>    
  </application>
</server>