把一些全局的参数配置到配置文件里面,把全局属性注入到类里面,由程序代码直接引用.
普通引入properties方法(只介绍)
在spring的配置文件applicationContext.xml
配置
<bean id=
"propertyConfigurer"
class=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations"> <list> <value>classpath:config.properties</value> </list> </property> <
/bean>
改进后的properties引入方法
在spring的配置文件applicationContext.xml
配置
<bean id=
"configProperties"
class=
"org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations"> <list> <value>classpath*:config.properties</value> </list> </property> <
/bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties" ref="configProperties"></property>
</bean>
config.properties文件配置内容
扫描二维码关注公众号,回复:
3593712 查看本文章
# 变量
maxid=12342
JAVA类的使用示例
"#{configProperties['maxid']}")
private int maxid;
(