本文介绍了WebSphere和PropertyPlaceholderConfigurer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是属性的大用户(使用PropertyPlaceholderConfigurer),使我的应用程序尽可能动态".几乎所有的常量都是这样定义的.无论如何,我目前正在定义default.properties,它随默认WAR一起提供.

I'm a big user of properties (with PropertyPlaceholderConfigurer) for making my application as "dynamic" as possible. Almost all the constants are defined as such. Anyway, I'm currently defining a default.properties which comes shipped with the default WAR.

在其他环境(验收/生产)中,我需要覆盖配置.我正在这样做,如下所示:

In other environments (Acceptance/Production) I need to overwrite of the configurations. I'm doing this as following:

<bean id="propertyManager"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:com/company/default.properties</value>
                <value>file:${COMPANY_PROPERTIES_LOCATION}\kbo-select-settings.properties</value>
            </list>
        </property>
    </bean>

这意味着我可以为每个环境使用可升级的构建.

With this means I can use a promotable build for each of the environments.

但是,我不喜欢无法从WebSphere内部更改任何属性这一事实.相反,我必须转到每个服务器(我们有8个集群)并相应地更改属性.如果我可以从WebSphere内部进行更改,然后再执行重新启动操作,那将对用户更加友好...

HOWEVER, I do dislike the fact that I can't change any of my properties from inside WebSphere. Instead I have to go to each of the servers (we have 8 clustered) and change the properties accordingly. It would be a lot more user friendly if I could change those from inside WebSphere and just perform a restart afterwards...

任何人都对如何进行这种可升级的构建有一个想法?我已经为数据源/java mail/etc定义了JNDI配置.

Anyone has an idea on how I could do such a promotable build? I already define JNDI configuration for datasources/java mail/etc.

谢谢!

推荐答案

我们通过在每种环境(本地,dev,int,tst ...)的属性文件上使用扩展名解决了这个问题,并且每个文件都包含特定值对于那些环境.然后,您唯一需要添加的是服务器上的VM参数来设置-Druntime.env = X.

We solved this problem by using an extension on the property file for each environment (local, dev, int, tst ...) and each file contained specific values for those environments. The only addition you then require is a VM argument on the server to set -Druntime.env=X.

您在配置文件中的查找将如下所示

Your lookups in your config file will then look like this

<bean id="propertyManager"
 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
       <list>
          <value>classpath:com/company/default.properties.${runtime.env}</value>
          <value>file:${COMPANY_PROPERTIES_LOCATION}\kbo-select-settings.properties</value>
        </list>
    </property>
 </bean>

当然,这仅在您具有相当静态的环境时才有效,因为它仍然无法在运行时进行更改,但确实会使升级应用程序变得很简单.如果您希望能够在不重新部署应用程序的情况下更改值,则必须将其存储在应用程序外部,这似乎已经在 kbo-select-settings.properties

Of course this only works if you have fairly static environments, as it still doesn't lend itself to changing it at runtime, but it does makes promotion of the application dead simple. If you want to be able to change the values without redeploying your application, you will have to have them stored outside your application, which you already seem to be doing for the kbo-select-settings.properties

这篇关于WebSphere和PropertyPlaceholderConfigurer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 14:33