有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpringConfig是否能够从自定义变量解析器解析变量?

在。net spring land您可以在spring配置中声明自定义变量源并执行${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中,这与什么是等价的


共 (1) 个答案

  1. # 1 楼答案

    您也可以在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>