JavaSpringConfig是否能够从自定义变量解析器解析变量?
在.NETSpringLand中,您可以声明一个自定义变量源,并在spring配置中使用JavaSpringConfig是否能够从自定义变量解析器解析变量?,java,spring,variables,configuration,Java,Spring,Variables,Configuration,在.NETSpringLand中,您可以声明一个自定义变量源,并在spring配置中使用${variableName}样式变量。您可以通过实现一个接口(IVariableSource)来实现它,它如下所示: <object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core"> <property name="VariableSources">
${variableName}
样式变量。您可以通过实现一个接口(IVariableSource
)来实现它,它如下所示:
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<ref object="MyVariableSource" />
</list>
</property>
</object>
<object id="TestObject" type="TestProject.TestObject, TestProject" singleton="false">
<constructor-arg type="string" value="${MyVariableDefinedInMyVariableSource}" />
</object>
在java spring land中,这与什么是等价的?您也可以在
java
中实现同样的效果。下面是一个例子
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config/config.properties" />
</bean>
<bean id="myController"
<property name="variableName" value="${variableName}" />
</bean>
谢谢,我看到了PropertyPlaceHolderConfigure的文档,但不完全一样。我不是从属性文件而是从数据库读取值