我试图使用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
更多推荐
如何在春天外部化配置?
发布评论