spring中<context:annotation-config/>配置的作用,现记录如下:

<context:annotation-config/>的作用是向Spring容器注册以下四个BeanPostProcessor:

  • AutowiredAnnotationBeanPostProcessor
  • CommonAnnotationBeanPostProcessor
  • PersistenceAnnotationBeanPostProcessor
  • RequiredAnnotationBeanPostProcessor

那么,为什么要注册这四个BeanPostProcessor呢?是为了让系统能够识别相应的注解。 例如:

1、如果想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。

传统声明方式如下:

<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/> 

2、如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor  Bean。

3、如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。

4、如果想使用@Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。

以上这些注解是很常用的,如果按照传统的方式进行配置将会非常繁琐,所以Spring给我们提供了一个简便的方式:<context:annotation-config/>,使用该元素可以自动声明以上注解。

注:由于<context:component-scan base-package=”xx.xx”/>也包含了自动注入上述Bean的功能,所以<context:annotation-config/> 可以省略。如果两者都进行了配置,则只有前者有效。

注:

<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解。

<context:component-scan>除了具有<context:annotation-config>的功能之外,<context:component-scan>还可以在指定的package下扫描以及注册javabean 。

Spring中<context:annotation-config/>的作用的更多相关文章

  1. Spring中<context:annotation-config/>

    最近在研究Spring中<context:annotation-config/>配置的作用,现记录如下: <context:annotation-config/>的作用是向Sp ...

  2. spring中context:property-placeholder/元素 转载

    spring中context:property-placeholder/元素  转载 1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,passwo ...

  3. spring中 context:property-placeholder 导入多个独立的 .properties配置文件

    spring中 context:property-placeholder 导入多个独立的 .properties配置文件? Spring容器采用反射扫描的发现机制,在探测到Spring容器中有一个 o ...

  4. Spring中 <context:property-placeholder 的使用与解析 .properties 配置文件的加载

    转: Spring中property-placeholder的使用与解析 Spring中property-placeholder的使用与解析 我们在基于spring开发应用的时候,一般都会将数据库的配 ...

  5. Spring 中context.start作用

    我们经常会看到 如下代码 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configPath. ...

  6. spring中context:property-placeholder/元素

    1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,password,driverClass等 b.分布式应用中client端访问server端所用的 ...

  7. Spring中各个jar包的作用

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...

  8. Spring中通过Annotation来实现AOP

    一.Spring配置文件 <!--通过@AspectJ注解的形式来使用Spring AOP,强制使用CGLIB代理--> <aop:aspectj-autoproxy proxy-t ...

  9. spring中context:property-placeholder

    发现网上对于这个标签的解释过于复杂,这里从实用性角度简短的进行说明. 首先,它是spring3中提供的标签. 只需要在spring的配置文件里添加一句: <context:property-pl ...

随机推荐

  1. (转)数位dp

    原博客 https://blog.csdn.net/wust_zzwh/article/details/52100392 建议原博客看到hdu 不要62,然后看我分割线后两道题,然后再回来看原博.-- ...

  2. Linux总线设备驱动模型

    1. Linux2.6内核引入总线.设备.驱动模型来描述各种总线(PCI.USB.I2C.SPI)与外围设备及其驱动之间的关系. 2. 在Linux内核中,总线用bus_type结构来描述,定义于文件 ...

  3. Maven系统学习

    1. 1.1 何为构建? 编译.测试.运行.打包.部署等工作: Maven就是用软件的办法让这一系列工作自动化,只需要一条简单的命令,所有繁琐的工作就会自动完成: Maven最大的消除了构建的重复,抽 ...

  4. Epplus导出Excel(DataTable)

    1.先将dataTable转换成流 public Stream DataTableToExcel(DataTable dataTable, string[] columns, string sheet ...

  5. 枚举类型与字符串ConvertEnumToString

    枚举类型与字符串添加字典互转ConvertEnumToString using UnityEngine; using System.Collections; using UnityEngine.UI; ...

  6. [转]Show parameter & Table Not exists

    本文转自:http://www.cnblogs.com/fangwenyu/archive/2011/01/06/1926774.html 问题描述 在尝试通过show parameter来查看一个参 ...

  7. ThinkPHP3.2 整合支付宝RSA加密方式

    RSA核心加密验证算法 <?php /** * RSA签名 * @param $data 待签名数据 * @param $private_key 商户私钥字符串 * return 签名结果 */ ...

  8. c#-foreach的秘密

    foreach的秘密 class Program { static void Main(string[] args) { //创建Person的对象 Person p1=new Person(); / ...

  9. C# url获取图片流转字符串

    //http url获取图片流转字符串 //string url = serverUrl.TrimEnd('/') + PUrl; //WebRequest request = WebRequest. ...

  10. SOAP介绍,为学习WCF做准备

    SOAP 1.什么是SOAP? 答:简单对象访问协议是交换数据的一种协议规范,是一种轻量的.简单的.基于XML的协议, 它被设计成在WEB上交换结构化的和固化的信息.WebService的三要素 SO ...