context:annotation-config, mvc:annotation-driven, context:compont-scan 区别
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如:
使用@Autowired注解,必须事先在Spring容器中声明AutowiredAnnotationBeanPostProcessor的Bean:
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/>
使用 @Required注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean:
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
类似地,使用@Resource、@PostConstruct、@PreDestroy等注解就必须声明 CommonAnnotationBeanPostProcessor;使用@PersistenceContext注解,就必须声明 PersistenceAnnotationBeanPostProcessor的Bean。
这样的声明未免太不优雅,而Spring为我们提供了一种极为方便注册这些BeanPostProcessor的方式,即使用<context:annotation- config/>隐式地向 Spring容器注册AutowiredAnnotationBeanPostProcessor、RequiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor以及PersistenceAnnotationBeanPostProcessor这4个BeanPostProcessor。如下:
<context:annotation-config/>
另,在我们使用注解时一般都会配置扫描包路径选项:
<context:component-scan base-package="pack.pack"/>
该配置项其实也包含了自动注入上述processor的功能,因此当使用<context:component-scan/>后,即可将<context:annotation-config/>省去。
<mvc:annotation-driven/>
相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。
<mvc:annotation-driven/> is a tag added in Spring 3.0 which does the following:
1. Configures the Spring 3 Type ConversionService (alternative to PropertyEditors)
2. Adds support for formatting Number fields with @NumberFormat
3. Adds support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath
4. Adds support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath
5. Adds support for support for reading and writing XML, if JAXB is on the classpath (HTTP message conversion with @RequestBody/@ResponseBody)
6. Adds support for reading and writing JSON, if Jackson is o n the classpath (along the same lines as #5)
context:annotation-config, mvc:annotation-driven, context:compont-scan 区别的更多相关文章
- <context:annotation-config/>,<mvc:annotation-driven/>和<context:component-scan>之间的关系
首先看一下三个注解各自定义: ① <context:annotation-config/> 1.如果你想使用@Autowired注解,那么就必须事先在 spring 容器中声明 Autow ...
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
在写一个使用spring3 的form标签的例子时,一直报错,错误信息为:java.lang.IllegalStateException: Neither BindingResult nor plai ...
- context:component-scan 和 mvc:annotation-driven
前言 Spring MVC 框架提供了几种不同的配置元素来帮助和指示 Spring 容器管理以及注入 bean . 常用的几个 XML 配置是 context:component-scan mvc:a ...
- [Spring MVC] - Annotation验证
使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotat ...
- <mvc:annotation-driven />与<context:annotation-config />
Spring家族的配置中这两个配置的意义,说具体点其实根据标签的shecma就能看出来,mvc,主要就是为了Spring MVC来用的,提供Controller请求转发,json自动转换等功能,而co ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
严重: StandardWrapper.Throwableorg.springframework.beans.factory.BeanCreationException: Error creating ...
- Spring < context:annotation-config> 、< context:component-scan>、< mvc:annotation-driven />注解配置
Spring 中在使用注解(Annotation)会涉及到< context:annotation-config> 和 < context:component-scan>配置, ...
- <mvc:annotation-driven/>与<context:annotation-config/>的区别
在使用注解的方式配置SSM的时候一般会配置<mvc:annotation-driven/>与<context:annotation-config/>,有时候会对两者的概念有些区 ...
- context、config
Tomcat启动时已经创建了context,并使用它读取了web.xml中的参数,后台可以从context里获取参数 后台获取参数代码: ServletContext context = getSer ...
- 使用context来传递数据,一个context是一系列变量
页面设计工作和python代码分离,所以我们引用模板来实现这个功能. 一.模板实例 下面是一个模板的实例: [python]<html><head><title>O ...
随机推荐
- 微信小程序下拉刷新和上拉加载
小程序知识点二 1.上拉加载和下拉刷新 Wxml文件 <scroll-view scroll-top="{{scrollTop}}" scroll-y="true& ...
- sencha cmd常用命令汇总
一.sencha generate:自动生成项目或者代码 1.sencha generate app 项目名称 生成路径 :生成一个新的extjs项目 注明:以上命令会从官网下载试用版本的ext代码到 ...
- 【iScroll源码学习01】准备阶段 - 叶小钗
[iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文 http://www.cnblogs.com/yexiaochai/p/3 ...
- Windows Server 2012 安装sqlserver2008 小记
1.拷贝大文件被阻止 解决方案:把大文件压缩成小文件... 据说关闭防火墙会好点,没试验过. 2.安装第一步,提示没有安装.net framework 3.5 sp1 ,使用服务器管理器,添加角色 ...
- iOS动画特效
关于图层的几个坐标系. 对于ios来说,坐标系的(0,0)点在左上角,就是越往下,Y值越大.越往右,X值越大. 一个图层的frame,它是position,bounds,anchorPoint和tra ...
- 浅谈IOS8之size class
文章目录 1. 简介 2. 实验 3. 实战 3.1. 修改 Constraints 3.2. 安装和卸载 Constraints 3.3. 安装和卸载 View 3.4. 其他 4. 后话 以前和安 ...
- IO文件
在Windows下的路径分隔符和Linux下的路径分隔符是不一样的,当直接使用绝对路径时,跨平台会暴出“No such file or diretory”的异常. Separator: 比如说要在te ...
- java制作二维码的两种方式
原博:http://www.importnew.com/15028.html Zebra Crossing(ZXing)是一个很棒的,几乎可以在所有平台(Android.JavaSE.iPhone.R ...
- DOMContentLoaded
setTimeout(function(){ alert("settimeout"); },0); EventUtil.addHandler(window, "DOMCo ...
- PHP获取图片颜色值
PHP获取图片颜色值,检测图片主要颜色的代码: <?php $i=imagecreatefromjpeg("photo3.jpg");//测试图片,自己定义一个,注意路径 f ...