Spring - 如何让app从属性文件中读取环境变量

时间:2021-05-28 23:50:17

I have several Spring based apps - web, web services

我有几个基于Spring的应用程序 - 网络,Web服务

For my web services project, in my ws-config.xml file, I specify the location of the wsdl. This has been set to localhost in the past, but I now need to have this as a configurable value in a properties file if I can.

对于我的Web服务项目,在我的ws-config.xml文件中,我指定了wsdl的位置。这已经被设置为localhost了,但是如果可以的话,我现在需要将它作为属性文件中的可配置值。

<ws:dynamic-wsdl id="ServiceDefinition"
    portTypeName="Test" locationUri="http://localhost/Test/webservice">
    <ws:xsd location="/WEB-INF/schemas/my-test.xsd" />
</ws:dynamic-wsdl>

I need to be able to reference the locationUri as a property, but I dont know how to do it?

我需要能够将locationUri作为属性引用,但我不知道该怎么做?

Can anyone help?

有人可以帮忙吗?

1 个解决方案

#1


0  

Check out the PropertyPlaceHolderConfigurer. You can use this to specify properties in your Spring configs, and specify which properties sources to populate this property from. You can specify a hierarchy of sources, such that (say) you have a file of default properties, and then some overridden values in a per-user config.

查看PropertyPlaceHolderConfigurer。您可以使用它来指定Spring配置中的属性,并指定要从中填充此属性的属性源。您可以指定源的层次结构,以便(比方说)您拥有默认属性的文件,然后在每个用户的配置中使用一些被覆盖的值。

Here's a trivial example.

这是一个简单的例子。

#1


0  

Check out the PropertyPlaceHolderConfigurer. You can use this to specify properties in your Spring configs, and specify which properties sources to populate this property from. You can specify a hierarchy of sources, such that (say) you have a file of default properties, and then some overridden values in a per-user config.

查看PropertyPlaceHolderConfigurer。您可以使用它来指定Spring配置中的属性,并指定要从中填充此属性的属性源。您可以指定源的层次结构,以便(比方说)您拥有默认属性的文件,然后在每个用户的配置中使用一些被覆盖的值。

Here's a trivial example.

这是一个简单的例子。