有没有办法在 Websphere 中传递特定于应用程序的属性?

问题描述:

我们有一个 websphere 应用程序服务器,其中部署了多个应用程序.所有应用程序都使用一个共同的属性(Key),但具有不同的值.例如 :spring.profiles.active=test 在一个应用程序中, spring.profiles.active=UAT 在其他一些应用程序中.是否可以在 Websphere 启动期间将这些不同的值传递给应用程序?

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 ?

如果我们在 Generic JVM Arguments 文本框中的 JVM 选项中设置这些值,那么对于我们不想要的所有应用程序,它都会变得相同.

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.

在 websphere 的应用程序级别设置这些属性,以便在应用程序启动时 -对于应用程序 1 - spring.profiles.active=test对于应用程序 2 - spring.profiles.active=UAT

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

本文档表明您可以在每个 Web 应用程序的 WebApplicationInitializer 中设置 spring.profiles.active 属性.然后,每个应用程序都可以从系统属性中读取自己特定命名的属性.或者,如果使用 Liberty(问题没有在传统 WebSphere 与 Liberty 之间指定),那么您可以使用 MicroProfile Config 来定义具有通用名称的属性,该名称通过 appProperties 为每个应用程序定义不同,例如 这篇知识中心文章.但是您仍然需要 WebApplicationInitializer 来从 MicroProfile 配置读取值.

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.

示例如下:

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

server.xml:

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>