谏知中文网

悟已往之不谏,知来者之可追

PropertyPlaceholderConfigurer 无效的问题

发表于 2018-08-09 3246 次浏览

Spring读取Properties文件

<context:property-placeholder location="classpath:db.properties"/>

我本地用的Spring-beans-5.2.3无法使用<context:property-placeholder/>属性,因为PropertyPlaceholderConfigurer已经被弃用,使用其他方式:

<bean id="propertyConfigurer" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" value="classpath:db.properties"></property>
    <property name="fileEncoding" value="utf-8"></property>
</bean>

需要配置resources类路径