(一)Controller 中 通过@value 读取properties配置信息
1、springmvc-servlet.xml 中配置:
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:basicmanagement.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
2、basicmanagement.properties中配置参数
sessionTimeOut = 60
3、Controller 获取方式
@Value("#{configProperties['sessionTimeOut']}")
private int sessionTimeOut;
(二)Service 中 通过@value 读取properties配置信息
1、applicationContext.xml中的配置
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:basicmanagement.properties" />
</bean>
2、Service 获取方式
@Value("${sessionTimeOut}")
private int sessionTimeOut;