【发布时间】:2013-09-13 09:02:43
【问题描述】:
我正在尝试使用 spring 将配置外部化,但无法使其正常工作..
这是我到目前为止所做的:
在每个环境的 war 文件 (src/test/resources/) 中创建一个属性文件。 例如:nonprod-key.properties & prod-key.properties,内容如下:
key.name=NameOfPrivateKey.pfx
key.password=JustAPasswordForPrivateKey
然后在我的jboss-cxf.xml中,我想读取上面的值如下:
<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
-Denvironment=nonprod
不幸的是,上述方法不起作用。 :(
我收到此错误消息:
class path resource [#{systemProperties['environment']}-key.properties] cannot be opened because it does not exist
但似乎无法让它工作。我究竟做错了什么? 有人可以举例说明如何最好地做到这一点。
谢谢。
-SGB
【问题讨论】:
-
显然模板无法转换为正确的资源名称。考虑使用配置文件而不是您的方法。
-
hmm.. 你有我可以使用的示例代码吗?从这个链接听起来应该是可能的:forum.springsource.org/…?
-
我想你需要一个
PropertyPlaceholderConfigurer才能工作。考虑this
标签: java spring configuration