如何在春天外部化配置?

编程入门 行业动态 更新时间:2024-10-14 18:17:46
本文介绍了如何在春天外部化配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用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

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

I was attempting to use the suggestion from here : forum.springsource/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

更多推荐

如何在春天外部化配置?

本文发布于:2023-11-25 20:42:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:春天   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!