首页 > 编程语言 > 详细

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

时间:2014-09-10 10:47:10      阅读:455      评论:0      收藏:0      [点我收藏+]

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简化配置文件的读取

原文:http://www.cnblogs.com/BensonHe/p/3963940.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!