在spring 的xml文件里面加入以下描述,并且 property name属性 locations及fileEncoding名字不能改变 bean id名字可以改变。
<property name="fileEncoding" value="UTF-8"></property> 保证可注入中文
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
<property name="fileEncoding" value="UTF-8"></property>
</bean>
在需要使用properties里面的值时,使用${propertiesKey}
<property name="name" value="${config.name}"></property>
<property name="id" value="${congig.id}"></property>
config.properties配置文件:
congig.id=5218
config.name=易家享