SpringMVC配置项学习笔记
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配置项学习笔记的更多相关文章
- SpringMVC框架学习笔记(6)——拦截器
SpringMVC拦截器需要实现接口HandlerInterceptor 有3个方法,分别在请求处理前.请求处理后和在DispatcherServlet处理后执行 实现代码: package inte ...
- SpringMVC框架学习笔记(1)——HelloWorld
搭建SpringMVC框架 1.添加jar包 jsp-api.jar servlet-api.jar jstl.jar commons-logging-1.1.1.jar spring-beans-4 ...
- SpringMVC框架学习笔记(2)——使用注解开发SpringMVC
1.配置web.xml <servlet> <servlet-name>mvc</servlet-name> <servlet-class>org.sp ...
- SpringMVC框架学习笔记(4)——结果跳转方式
1.设置ModelAndView对象.根据View和视图解析器跳转到指定页面(视图解析器前缀+viewname+视图解析器后缀) @Override public ModelAndView handl ...
- SpringMVC详细学习笔记
Spring MVC 1 spring MVC简介: Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构 ...
- 《springMVC》学习笔记
1.SpringMVC框架 1.1 MVC在b/s系统下的应用 用户发送request请求到Controller Controller请求模型(Model)进行处理 Model将处理结果返回到Cont ...
- 兄弟萌,这份SpringMVC框架学习笔记真的建议反复看,写的太细了
概述 是Spring为展现层提供的基于MVC设计理念的Web框架,通过一套MVC注解,让POJO成为处理请求的控制器,而无需实现任何接口 支持REST风格的URL请求 采用松散耦合的可插拔组件结构,比 ...
- SpringMVC框架学习笔记(5)——数据处理
1.提交数据的处理 a)提交的域名称和参数名称一致 http://localhost:8080/foward/hello.do?name=zhangsan 处理方法 @RequestMapping(v ...
- SpringMVC框架学习笔记——各种异常、报错解决
1.Target runtime com.genuitec.runtime.generic.jee60 is not defined. 找到导入项目的.setting文件夹org.eclipse.ws ...
随机推荐
- Spring事务
1.@Transactional 只能被应用到public方法上, 对于其它非public的方法,如果标记了@Transactional也不会报错,但方法没有事务功能.@Transactional 的 ...
- Html 基础介绍 基础标签
<head> <!-- 设置编码格式 --> <meta charset="UTF-8"> <!-- 设置作者 --> <me ...
- Codeforces CF#628 Education 8 E. Zbazi in Zeydabad
E. Zbazi in Zeydabad time limit per test 5 seconds memory limit per test 512 megabytes input standar ...
- HTML5 学习笔记(二)——HTML5新增属性与表单元素
目录 一.HTML5新增属性 1.1.contextmenu 1.2.contentEditable 1.3.hidden 1.4.draggable 1.5.data-* 1.6.placehold ...
- VB6+Winsock编写的websocket服务端
早就写好了,看这方面资料比较少,索性贴出来.只是一个DEMO中的,没有做优化,代码比较草.由于没地方上传附件,所以只把一些主要的代码贴出来. 这只是服务端,不过客户端可以反推出来,其实了解了webso ...
- 我的前端故事----Ajax方式和jsonp的实现区别
很久没有更新博客了,毕业2个月了,这段时间一直在忙于工作,一直没有时间更新,最近做的活动突然发现之前的经验居然忘记了...索性想想还是重新开始用博客记录平日里的工作经验吧,吐槽就到这里了,这篇记录的是 ...
- js中自定义构造函数讲解
什么是构造函数? 构造函数其实就是一个函数,只是用途和普通函数,不太一样, 构造函数一般用于初始化对象 <script> function Person(){ this.name=&quo ...
- lua 字符串 正则表达式 转义 特殊字符
string.gsub 函数有三个参数:目标串,模式串,替换串.基本作用是用来查找匹配模式的串,并将使用替换串其替换掉: s = string.gsub("Lua is good" ...
- Python基本数据类型——str
字符串常用操作 移除空白 分割 长度 索引 切片 class str(basestring): """ str(object='') -> string Retur ...
- ajax知识整理
HTTP服务 1.服务器 服务器类型 服务类型:文件服务器.数据库服务器.邮件服务器.Web服务器等: 操作系统:Linux服务器.Windows服务器等: 应用软件:Apache服务器.Nginx ...