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. windows知识点2

    最近在使用win10系统的过程中,无法获取dns报错,上不了网.经过一番折腾,最终在用下面的方法,解决了问题.第二步很关键.完成步一下步骤重启电脑应该就可以上网了.12第一步:使用 ipconfig ...

  2. day01知识点

    1.计算机基础 2.Python的历史 3.编码语言分类     Python是一门动态解释性的强制类型定义语言 4.Python的解释器种类 5.变量     法律规则:字母,数字,下划线(数字不能 ...

  3. mysql 视图 安全性( mysql 表能读,但是视图不能读问题 )

    安全性: 有两个选项 Definer:定义者 , 定义者有什么权限 ,访问视图的人就有什么权限 Invoker: 调用者  ,根据调用这个视图的当前用户来决定 有什么权限 采坑: 项目中有个复杂查询. ...

  4. 【java】异常

    异常体系:Throwable ---Error 通常出现重大问题:如类不存在或者内存溢出.停止运行,不对代码进行处理 ---Exception 在运行时出现的情况,可以进行针对性处理.可以通过try ...

  5. Thread.Abort 方法

    [SecurityPermissionAttribute(SecurityAction.Demand, ControlThread = true)] public void Abort() 在调用此方 ...

  6. UEFI引导过程及windows引导修复

    UEFI启动是一种新的主板引导项.传统引导方式就是Legacy模式. CSM的选项是UEFI模拟Legacy模式启动,选中后则可使用Legacy模式启动机器. Legacy模式仅支持传统的MBR分区, ...

  7. mac中更改xampp的根目录

    方法一: 1 打开 应用程序->XAMPP->xamppfiles->etc->httpd.conf 文档 2 commond+f搜索htdocs,搜到如下结果 # Docum ...

  8. Livepeer中文白皮书(翻译)

    Livepeer Whitepaper 分布式视频流媒体传输协议及经济激励 Doug Petkanics doug@livepeer.org Eric Tang eric@livepeer.org 翻 ...

  9. python with as的用法

    With语句是什么? 有一些任务,可能事先需要设置,事后做清理工作.对于这种场景,Python的with语句提供了一种非常方便的处理方式.一个很好的例子是文件处理,你需要获取一个文件句柄,从文件中读取 ...

  10. Layout-2相关代码:3列布局代码演化[一]

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...