【发布时间】:2021-05-17 20:04:28
【问题描述】:
我有 许多 类消耗 java.util.properties 类型的资源,但现在,不同的属性文件具有环境变量,例如:
com.something.one=AAA1
com.something.two=${MyEnvVar}
com.something.url=http://${myhost}:${myport}/xxx/yyy/zzz
我的课是这样的:
public class MyTest {
@Resource(name="utilProp")
private Properties prop;
public void init() {
System.out.println("var one = "+prop.getProperty("com.something.one"));
System.out.println("var two = "+prop.getProperty("com.something.two"));
System.out.println("var url = "+prop.getProperty("com.something.url"));
用这个 Bean:
<util:properties id="utilProp" location="classpath:myProp.properties"/>
我有这个结果:
var one = AAA1
var two = ${MyEnvVar}
var url = http://${myhost}:${myport}/xxx/yyy/zzz
如何定义一个与 Java.util.Properties 兼容但也读取环境变量的 Bean?
类似:
<beans:bean id="utilProp" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<beans:property name="searchSystemEnvironment" value="true" /> //This not exists here !!! :(
<beans:property name="locations">
<beans:list>
<beans:value>classpath:myProp.properties</beans:value>
</beans:list>
</beans:property>
</beans:bean>
【问题讨论】:
标签: java spring properties environment-variables