码迷,mamicode.com
首页 > 编程语言 > 详细

使用Spring 3的@value简化配置文件的读取

时间:2017-07-13 21:54:45      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:color   读取   framework   bean   classpath   private   crawl   ace   配置文件   

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;

即使给变量赋了初值也会以配置文件的值为准。

使用Spring 3的@value简化配置文件的读取

标签:color   读取   framework   bean   classpath   private   crawl   ace   配置文件   

原文地址:http://www.cnblogs.com/xujingyang/p/7163123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!