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. I.MX 6UL与6ULL应用领域区别

  2. Computer Graphics Principles And Practice (James Foley / Andries Van Dam / Morgan McGuire / David Sklar / James D. Foley 著)

    1 Introduction 2 Introduction to 2D Graphics Using WPF 3 An Ancient Renderer Made Modern 4 A 2D Grap ...

  3. w3c

    normative    adj. 规范的,标准的errata        n. 勘误表:正误表(erratum的复数)Substantive    adj. 有实质的:大量的:真实的:独立存在的i ...

  4. Vue 错误记录:Cannot read property 'beforeRouteEnter' of undefined

    点击某路由链接,页面提示: Cannot read property 'beforeRouteEnter' of undefined 查看代码并无手写beforeRouterEnter设置, 把页面内 ...

  5. [转]Linux编译和安装boost库

    1. 下载boost安装包并解压缩 到http://www.boost.org/下载boost的安装包,以boost_1_58_0.tar.gz为例 下载完成后进行解压缩: tar zxvf boos ...

  6. Spring Cloud Alibaba正式入驻Spring Cloud官方孵化器

    第一个版本发布内容如下: 开源组件(spring-cloud-alibaba开头): 服务发现(Service Discovery) 配置管理(Configuration Management) 高可 ...

  7. Linux shell 重定向学习笔记

    在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以实现文件的读 ...

  8. 在虚拟机上配置安装hadoop集群

    原本以为有大神已经总结的很清楚了,就不自己在写了, 但是在自己安装的过程中还是出现了一些问题, 所以打算以自己的方式重新总结一下.    参考https://blog.csdn.net/hliq539 ...

  9. OpenCV中feature2D——BFMatcher和FlannBasedMatcher

    作者:holybin 原文:https://blog.csdn.net/holybin/article/details/40926315 Brute Force匹配和FLANN匹配是opencv二维特 ...

  10. SpringBoot启动源码探究---listeners.starting()

    1.首先调用starting()方法,其内部是一个对所有listener的starting()调用的for循环,然后每个listener调用另一个starting方法,其内部调用multicastEv ...