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的@value注解的更多相关文章

  1. Spring+Mybatis基于注解整合Redis

    基于这段时间折腾redis遇到了各种问题,想着整理一下.本文主要介绍基于Spring+Mybatis以注解的形式整合Redis.废话少说,进入正题. 首先准备Redis,我下的是Windows版,下载 ...

  2. Spring MVC常用注解

    cp by http://www.cnblogs.com/leskang/p/5445698.html 1.@Controller 在SpringMVC 中,控制器Controller 负责处理由Di ...

  3. 利用spring AOP 和注解实现方法中查cache-我们到底能走多远系列(46)

    主题:这份代码是开发中常见的代码,查询数据库某个主表的数据,为了提高性能,做一次缓存,每次调用时先拿缓存数据,有则直接返回,没有才向数据库查数据,降低数据库压力. public Merchant lo ...

  4. Spring中@Autowired注解、@Resource注解的区别

    Spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@PostConstruct以及@PreDestroy. @Resour ...

  5. spring mvc3的注解@ResponseBody 自动返回jason

    第三种利用spring mvc3的注解@ResponseBody 例如: @ResponseBody @RequestMapping("/list") public List< ...

  6. 基于spring mvc的注解DEMO完整例子

    弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件.本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mv ...

  7. 转:Spring中@Autowired注解、@Resource注解的区别

    Pay attention: When using these annotations, the object itself has to be created by Spring context. ...

  8. spring aop 使用注解方式总结

    spring aop的注解方式:和xml的配置方式略有区别,详细如下: 1.首先还是建立需要的切面类:切面类里面定义好切点配置,以及所有的需要实现的通知方法. /** * */ package com ...

  9. spring mvc 基于注解的使用总结

    本文转自http://blog.csdn.net/lufeng20/article/details/7598801 概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Sprin ...

  10. 利用Spring AOP自定义注解解决日志和签名校验

    转载:http://www.cnblogs.com/shipengzhi/articles/2716004.html 一.需解决的问题 部分API有签名参数(signature),Passport首先 ...

随机推荐

  1. Android Theme主题

    •android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式 •android:theme="@and ...

  2. js之语句的一些需要注意的事情

    1.delete运算符是用来删除一个对象的 属性,但有一点需要注意:使用var声明的变量虽为全局变量,单不是全局对象的属性,不可以用delete删除,而不用var直接声明的全局变量而直接赋值的为全局对 ...

  3. js 实现滑块效果

    var dd = $(".drag_bott").removeAttr('id').last().attr('id','drag_bott'); var drag = docume ...

  4. 【leetcode刷题笔记】Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题解:因为题 ...

  5. python实现并绘制 sigmoid函数,tanh函数,ReLU函数,PReLU函数

    Python绘制正余弦函数图像 # -*- coding:utf-8 -*- from matplotlib import pyplot as plt import numpy as np impor ...

  6. spring装配机制

    spring容器创建bean并通过DI(依赖注入)来协调他们之间的关系,他有三种装配机制: 1. 在XML中显式配置 2. 在Java文件中显式配置 3. 隐式的bean发现机制(组件扫描)和自动装配 ...

  7. hbase shell-dml(数据管理指令)

    hbase shell数据管理篇: append count delete deleteall get get_counter get_splits incr put scan truncate tr ...

  8. Ubuntu 16.04 NFS搭建

    NFS服务器配置: 1.安装NFS相关包 apt-get install nfs-kernel-server nfs-common # centos 7# yum install nfs-utils ...

  9. ELK常用API使用方法

    以下ELK系列文章参考自http://www.tianyiqingci.com/ 总目录: Monitor API ElasticSearch聚合分析API Elasticsearch信息检索API ...

  10. ELK的使用

    首先安装jdk,我这里使用open-jdk yum list all | grep jdk yum -y install java-1.8.0-openjdk-devel, java-1.8.0-op ...