Java 我们可以动态地将值传递给Springbean定义的参数吗?
我想从属性文件中读取Springbean定义中参数的值。可能吗 示例:persistanceUnitarg的值,在下面的bean定义中,我需要从属性文件中读取,或者以某种方式进行配置Java 我们可以动态地将值传递给Springbean定义的参数吗?,java,spring,Java,Spring,我想从属性文件中读取Springbean定义中参数的值。可能吗 示例:persistanceUnitarg的值,在下面的bean定义中,我需要从属性文件中读取,或者以某种方式进行配置 <bean id="profileDao" class="com.sample.dao.kundera.GenericKunderaDaoImpl"> <constructor-arg name="persistanceUnit" type="java.lang.Str
<bean id="profileDao" class="com.sample.dao.kundera.GenericKunderaDaoImpl">
<constructor-arg name="persistanceUnit" type="java.lang.String" value="cds_test_pu"/>
<constructor-arg name="persistentClass" type="java.lang.Class" value="com.sample.model.cds.Profile"/>
</bean>
如果spring已获取属性文件,则可以使用表达式引用属性:
<bean id="profileDao" class="com.sample.dao.kundera.GenericKunderaDaoImpl">
<constructor-arg name="persistanceUnit" type="java.lang.String" value="${cds_test_pu}"/>
<constructor-arg name="persistentClass" type="java.lang.Class" value="com.sample.model.cds.Profile"/>
</bean>
Spring boot有很多关于配置外部化的功能—请看这里:
如果spring已获取属性文件,则可以使用表达式引用属性:
<bean id="profileDao" class="com.sample.dao.kundera.GenericKunderaDaoImpl">
<constructor-arg name="persistanceUnit" type="java.lang.String" value="${cds_test_pu}"/>
<constructor-arg name="persistentClass" type="java.lang.Class" value="com.sample.model.cds.Profile"/>
</bean>
Spring boot有很多关于配置外部化的功能—请看这里:
添加到