1. <mvc:annotation-driven />

  <mvc:annotation-driven />是一种简写形式,默认会注册DefaultAnnotationHandlerMapping和DefaultAnnotationHandlerAdapt两个bean,是spring mvc为@Controller分发请求所必须的,它还提供了@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持。也可以使用手动配置这两个bean,不过没有简写的这种方式方便。

2.<context:annotation-config />

  作用是向 Spring 容器注册AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。注册这4个BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解

  例如:

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

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

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

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

  (3)、如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor的bean。

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

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

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

  一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>的简化配置方式,自动帮你完成声明。

  不过,我们使用注解一般都会配置扫描包路径选项<context:component-scan base-package=”XX.XX”/>

该配置项其实也包含了自动注入上述processor的功能,因此当使用 <context:component-scan/> 后,就可以将 <context:annotation-config/> 移除了。

SpringMVC配置项学习笔记的更多相关文章

  1. SpringMVC框架学习笔记(6)——拦截器

    SpringMVC拦截器需要实现接口HandlerInterceptor 有3个方法,分别在请求处理前.请求处理后和在DispatcherServlet处理后执行 实现代码: package inte ...

  2. SpringMVC框架学习笔记(1)——HelloWorld

    搭建SpringMVC框架 1.添加jar包 jsp-api.jar servlet-api.jar jstl.jar commons-logging-1.1.1.jar spring-beans-4 ...

  3. SpringMVC框架学习笔记(2)——使用注解开发SpringMVC

    1.配置web.xml <servlet> <servlet-name>mvc</servlet-name> <servlet-class>org.sp ...

  4. SpringMVC框架学习笔记(4)——结果跳转方式

    1.设置ModelAndView对象.根据View和视图解析器跳转到指定页面(视图解析器前缀+viewname+视图解析器后缀) @Override public ModelAndView handl ...

  5. SpringMVC详细学习笔记

    Spring MVC   1 spring MVC简介:   Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构 ...

  6. 《springMVC》学习笔记

    1.SpringMVC框架 1.1 MVC在b/s系统下的应用 用户发送request请求到Controller Controller请求模型(Model)进行处理 Model将处理结果返回到Cont ...

  7. 兄弟萌,这份SpringMVC框架学习笔记真的建议反复看,写的太细了

    概述 是Spring为展现层提供的基于MVC设计理念的Web框架,通过一套MVC注解,让POJO成为处理请求的控制器,而无需实现任何接口 支持REST风格的URL请求 采用松散耦合的可插拔组件结构,比 ...

  8. SpringMVC框架学习笔记(5)——数据处理

    1.提交数据的处理 a)提交的域名称和参数名称一致 http://localhost:8080/foward/hello.do?name=zhangsan 处理方法 @RequestMapping(v ...

  9. SpringMVC框架学习笔记——各种异常、报错解决

    1.Target runtime com.genuitec.runtime.generic.jee60 is not defined. 找到导入项目的.setting文件夹org.eclipse.ws ...

随机推荐

  1. Swift 之模糊效果(毛玻璃效果,虚化效果)的实现

    前言: 之前项目中有用到过Objective-C的的模糊效果,感觉很是不错,而且iOS8之后官方SDK也直接提供了可以实现毛玻璃效果的三个类:UIBlurEffect.UIVibrancyEffect ...

  2. 采用Lambda表达式快速实现实体模型对象转换到DTO

    在项目中,采用code first时建立的模型对象不能直接用于数据传输,需要从新根据需求建立Dto对象 为什么需要建立Dto对象呢? DTO即数据传输对象.之前不明白有些框架中为什么要专门定义DTO来 ...

  3. Nodejs reactjs服务端渲染优化SEO

    一.准备动作 1.安装nodejs与安装express 安装nodejs教程:http://www.cnblogs.com/pigtail/archive/2013/01/08/2850486.htm ...

  4. PHP浮点数精度问题

    这一段时间维护一个类似团购的系统,需要处理订单,也就难免会处理金额 所以有很多PHP的坑 被我狠狠的踩了~~ 首先我们要知道浮点数的表示(IEEE 754): 简言之 就是 埋下了一个大坑 等着你跳 ...

  5. 基础2.Jquery过滤选择器

                         1.基础选择器: 名称 说明 举例 #id 根据元素Id选择 $("divId") 选择ID为divId的元素 element 根据元素的 ...

  6. Logback_日志使用详解(转)

    概述 Logback建立于三个主要类之上:日志记录器(Logger),输出端(Appender)和日志格式化器(Layout).这三种组件协同工作,使开发者可以按照消息类型和级别来记录消息,还可以在程 ...

  7. php留言

    使用yum安装php yum install pnp -y 安装httpd服务 yum install httpd -y 使用地三方软件将已经制作好的网站如"FileZilla"

  8. About_全在里面

    分享·地址:http://www.itxueyuan.org/view/6254.html

  9. 【转】stopPropagation, preventDefault 和 return false 的区别

    因为有父, 子节点同在, 因为有监听事件和浏览器默认动作之分. 使用 JavaScript 时为了达到预期效果经常需要阻止事件和动作执行. 一般我们会用到三种方法, 分别是  stopPropagat ...

  10. 使用THINKPHP中的控制器和模块查询数据库

    1,自定义一个UserController的控制器,导入tp的控制器与模块执行相应的操作. ----var_dump()方法是判断一个变量的类型与长度,并输出变量的数值,如果变量有值输的是变量的值. ...