方案一:
applicationContext-dao.xml中添加
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:properties/*.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
Service、Controller层调用代码:
@Value("#{configProperties['jdbc.url']}")
private String url;
方案二:
applicationContext-dao.xml、springmvc.xml中添加
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:properties/*.properties" />
Service、Controller层调用代码:
@Value("${jdbc.url}")
private String url;