如何在Spring Boot中将application.property值直接读取到另一个配置xml文件中

时间:2018-10-23 12:25:53

标签: java spring-mvc spring-boot classpath application.properties

我已经在applicaiton.properties文件中指定了一些Web服务端点,如下所示 application.properties

config.middleware.soap.service.endpoint.sample=http://xxx.xxx/sample/

现在,我想直接将这些值使用到另一个配置文件中,在本例中为root-context.xml文件,用于使用jax-ws客户端创建soap类。但是如果我从applicaiton.properties值引用它,则该属性不会被Spring Boot理解。为什么不?如果我直接提供端点,则可以正常工作。将application.properties文件的值用于其他配置文件的最简单方法是什么? root-context.xml

<jaxws:client id="sampleClient" serviceClass="com.sample.wsdl.sample"
        address="${config.middleware.soap.service.endpoint.sample}">

        ...
    </jaxws:client>

在我的情况下,root-context和application.properties文件都位于src / main / resources文件夹中。因此,我假定在应用程序启动时,这两个文件都加载到了类路径中。

1 个答案:

答案 0 :(得分:0)

当我以下面提到的方式使用它时,它终于工作了

<jaxws:client id="acctInqClient" serviceClass="com.ge.india.capital.wsdl.spine.AcctInq"
        address="#{environment['config.middleware.soap.service.endpoint.sample']}">

提供了,我在applicaiton.properties文件的名称config.middleware.soap.service.endpoint.sample中声明了一个属性。

但是我想知道为什么只有$ {config.middleware.soap.service.endpoint.sample}不起作用。谢谢。