如何在春天外部化配置? [英] How to externalize configuration in spring?

查看:139
本文介绍了如何在春天外部化配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用spring来外部化配置,但不能让它正常工作。

I am attempting to externalize the configurations using spring, but cannot get it to work properly..

这是我到目前为止做的:

Here is what I did so far:

在war文件(src / test / resources /)中为每个环境创建一个属性文件。
例如:nonprod-key.properties& prod-key.properties内容如下:

create a property file inside the war file (src/test/resources/) for each environment. For example: nonprod-key.properties & prod-key.properties with content like so:

    key.name=NameOfPrivateKey.pfx
    key.password=JustAPasswordForPrivateKey

然后在我的jboss-cxf.xml中,我想读取上面的值如下: / p>

Then in my jboss-cxf.xml, I would like to read the above value as follows:

    <import resource="#{systemProperties['environment']}-key.properties" />

    <http:conduit name="*.http-conduit">
        <http:tlsClientParameters
            secureSocketProtocol="SSL">
            <sec:keyManagers keyPassword="${key.password}">
                <sec:keyStore type="PKCS12" password="${key.password}" resource="${key.name}" />
            </sec:keyManagers>
            ...  ... ...
        </http:tlsClientParameters>
    </http:conduit>

然后在eclipse中,运行配置 - > Arguments - > VM Arguments

And then in eclipse, run configurations --> Arguments --> VM Arguments

    -Denvironment=nonprod

不幸的是,上面的不工作。 :(

Unfortunately, the above does not work. :(

我收到此错误消息:

    class path resource [#{systemProperties['environment']}-key.properties] cannot be opened because it does not exist

我试图使用这里的建议:
http://forum.springsource.org/showthread.php?98988-Access-external-properties-file-from-SPRING-context-file&p= 332278#post332278

I was attempting to use the suggestion from here : http://forum.springsource.org/showthread.php?98988-Access-external-properties-file-from-SPRING-context-file&p=332278#post332278

但似乎无法让它工作,我做错了什么?
有人可以给一个例子/样品如何最好地做到这一点。

But cannot seem to get it to work. What am I doing wrong? Could someone please give an example/sample of how best to do accomplish this.

谢谢。

-SGB

推荐答案

我相信需要在Spring 3.1.x上使用配置文件,我们还没有...。

I believe one needs to be on Spring 3.1.x to use profiles. We are not ... yet.

无论如何,最终的解决方案似乎对我们工作是使用:

Anyways, the final solution that seems to work for us is to use :

<context:property-placeholder location="classpath:${environment}-key.properties"/>

而不是

<import resource="#{systemProperties['environment']}-key.properties" />

其他都与我的原始帖子(问题)中列出的一样。

Everything else is same as listed in my original post (question).

希望有人认为这很有用。

Hope someone finds this useful.

SGB

这篇关于如何在春天外部化配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆