首先在配置文件中配置PropertyPlaceholderConfigurer
单个配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
[color=green] <property name="locations" value="classpath:jdbc.properties"/> [/color]
</bean>
多个配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
[color=green] <list>
<value>classpath:jdbc.properties</value>
<value>classpath:config.properties</value>
</list>[/color]
</property>
</bean>
然后在需要的地方直接以下方式引用:
[color=green]<property name="url" value="${jdbc.url}"/> [/color]
单个配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
[color=green] <property name="locations" value="classpath:jdbc.properties"/> [/color]
</bean>
多个配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
[color=green] <list>
<value>classpath:jdbc.properties</value>
<value>classpath:config.properties</value>
</list>[/color]
</property>
</bean>
然后在需要的地方直接以下方式引用:
[color=green]<property name="url" value="${jdbc.url}"/> [/color]