XML中context:annotation-config和context:component-scan简述


<context:annotation-config/>                           中文意思:<上下文:注解——配置/>

<context:component-scan base-package=" 扫描路劲"   annotation-config=true/>    中文意思:<上下文:部件——扫描  基础——包=“扫描路径”

注解——配置=true/>(annotation-config=true是默认的配置可省略不写)

1.<context:annotation-config/> 

<context:annotation-config/>配置的作用:是向Spring容器注册一次注入四个BeanPostProcessor

  • AutowiredAnnotationBeanPostProcessor
  • CommonAnnotationBeanPostProcessor
  • PersistenceAnnotationBeanPostProcessor
  • RequiredAnnotationBeanPostProcessor

AutowiredAnnotationBeanPostProcessor旧版注入方式<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>作用是能使用@Autowired注解

CommonAnnotationBeanPostProcessor旧版注入方式<bean class="org.springframework.beans.factory.annotation.CommonAnnotationBeanPostProcessor"/>作用是能使用@Resource、@PostConstruct、@PreDestroy注解;

PersistenceAnnotationBeanPostProcessor旧版注入方式<bean class="org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor"/>作用是能使用@PersistenceContext注解;

RequiredAnnotationBeanPostProcessor旧版注入方式<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>作用是能使用@Required注解;

<context:annotation-config/>的总结即在XML文件中配置<context:annotation-config/>不需要再配置上面四个ben对象;

2.<context:component-scan base-package=" 扫描路劲"   annotation-config=true/>

  作用:具有<context:component-config/>注解的功能,还能对指定的package下扫描以及注册javabean

Spring.xml中配置注解context:annotation-config和context:component-scan简述的更多相关文章

  1. Spring实战(十一) 在Spring XML中配置AOP

    如果你没有源码,不能为通知类添加注解,又不想将AspectJ注解放入到你的代码中,必须选择XML配置了. 1.Spring XML配置文件 解析参考:http://www.cnblogs.com/bi ...

  2. Spring xml中进行面向切面的配置

    Spring xml中进行面向切面的配置 XML: <?xml version="1.0" encoding="UTF-8"?> <beans ...

  3. 源码跟读,Spring是如何解析和加载xml中配置的beans

    Spring版本基于: 跟踪代码源码基于: https://github.com/deng-cc/KeepLearning commit id:c009ce47bd19e1faf9e07f12086c ...

  4. [spring]Bean注入——在XML中配置

    Bean注入的方式有两种: 一.在XML中配置 属性注入 构造函数注入 工厂方法注入 二.使用注解的方式注入@Autowired,@Resource,@Required 本文首先讲解在XML中配置的注 ...

  5. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

  6. 详解Java的Spring框架中的注解的用法

    转载:http://www.jb51.net/article/75460.htm 1. 使用Spring注解来注入属性 1.1. 使用注解以前我们是怎样注入属性的 类的实现: class UserMa ...

  7. Spring|SpringMVC中的注解

    文章目录 一.Spring注解 @Controller @ResuController @Service @Autowired @RequestMapping @RequestParam @Model ...

  8. 在web.xml中配置监听器来控制ioc容器生命周期

    5.整合关键-在web.xml中配置监听器来控制ioc容器生命周期 原因: 1.配置的组件太多,需保障单实例 2.项目停止后,ioc容器也需要关掉,降低对内存资源的占用. 项目启动创建容器,项目停止销 ...

  9. Spring MVC中@RequestMapping注解使用技巧(转)

    @RequestMapping是Spring Web应用程序中最常被用到的注解之一.这个注解会将HTTP请求映射到MVC和REST控制器的处理方法上. 在这篇文章中,你将会看到@RequestMapp ...

随机推荐

  1. Jmeter 传 PUT 请求方式

    最近用 Jmeter 发送 PUT 请求,踩了个坑,现记录如下: 难点在在于 body 内有一大串 json 形式的内容 1.PUT 请求的 body 内,直接将 json串传 form-data 形 ...

  2. 我发起了一个 用 javascript 写一个 Office 的 开源项目 JS Office

    用   js  写   Office,  说实在的,  把 现在已有的 各种 富文本编辑器 和 电子表格 js 库 收集起来 整合一下 就 差不多了 , 放到 前几天 那个 “  js 作为 一等公民 ...

  3. 手写SpringMVC实现

    设计自己的MVC架构 1.读取配置通过web.xml中加载我们自己写的MyDispatcherServlet和读取配置文件. 2.初始化九大组件只需实现基本的:1).加载配置文件:2).扫描用户配置包 ...

  4. ASP.NET: Cookie会话丢失,Session超时配置

    问题描述: asp.net应用中web.config的SessionState节点:原先是 <sessionState mode="InProc" timeout=" ...

  5. 开始转变方向,学习Linux——《Linux就该这么学》

    三十而立,四十不惑. 我呢,未立将不惑. 苦恼之余,决定拓展就业范围,正式学习Linux,准备考取RHCE证书. 考证需要报名培训机构,这是一个明智的选择,毕竟中国人善于考试,善于钻研考试. 联系培训 ...

  6. 函数中不能对全局变量进行修改,想要修改全局变量需要在变量前面加global

    # def change_name(name):#     global school    #     school = "Mage Linux"#     print(&quo ...

  7. KindEditor自动过滤首行缩进和全角空格的解决方法

    KindEditor 4.1.11:kindeditor-all.js 文件中大致第752行: /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?: ...

  8. locate中使用variant

    利用locate构造多字段查询,采用variant很方便,简介如下, //构造查询多字段,例如'编号;姓名'形式 aLookField :=  FieldByName ('关键字1').AsStrin ...

  9. Ubuntu 12.04 LTS 查看网关地址方法汇总

    来源:http://blog.csdn.net/duyiwuer2009/article/details/26263855 1. ip route show $ ip route show defau ...

  10. TensorFlow-GPU+cuda8+cudnn6+anaconda安装遇到的版本错误

    第一遍装的时候是cuda10+cudnn5.1这个诡异的组合,失败 卸载cuda就是把所有的NVIDIA有关的应用都删掉,c盘文件也都删掉,不用留. 第二遍是cuda8+cudnn5.1.版本还是对不 ...