有没有办法将 Spring 配置文件中 bean 的属性设置为从 Properties 文件中读取的字符串的属性?
例如
<bean id="...." class="....">
<property name="loginURL">GET_THIS_VALUE_FROM_'ENV.PROPERTIES'_FILE</property>
</bean>
最佳答案
您应该能够使用 PropertyPlaceHolderConfigurer加载属性文件,然后使用 Spring-EL 表达式引用属性 -
<context:property-placeholder location="classpath:custom.properties"/>
<bean id="...." class="....">
<property name="loginURL">${propname}</property>
</bean>
关于java - 在 Spring XML 配置文件中使用属性字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6352371/