Spring 3支持@value注解的方式獲取properties文件中的配置值,大簡化了讀取配置文件的代碼。
1、在applicationContext.xml文件中配置properties文件
<bean id="appProperty"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<array>
<value>classpath:app.properties</value>
</array>
</property>
</bean>
2、在bean中使用@value注解獲取配置文件的值
@Value("${chengmi_crawl_timer_enable}")
private Boolean timerEnabled;
即使給變量賦了初值也會以配置文件的值為准。

