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 ...
随机推荐
- 获取终端ip地址
网上找的,记录下 import java.io.*; import java.net.*; import java.util.*; //import org.apache.http.conn.util ...
- HTML5之文件API
问题很简单,做个上传文件的页面. <!-- multiple代表可上传多个文件 --> <input type="file" id="file" ...
- Android Handler消息传递机制
在Android系统中,类Handler主要有如下两个作用. 在新启动的线程中发送消息. 在主线程中获取.处理消息. 类Handler在实现上述作用时,首先在新启动的线程中发送消息,然后在主线程中获取 ...
- Kafka replication
Kafka replication kafka_replication_detailed_design_v2.pdf kafka Detailed Replication Design V3 Apac ...
- bzoj 3507: [Cqoi2014]通配符匹配
Description 几乎所有操作系统的命令行界面(CLI)中都支持文件名的通配符匹配以方便用户.最常见的通配符有两个,一个是星号(“”’),可以匹配0个及以上的任意字符:另一个是问号(“?”),可 ...
- CentOS 7 防止端口自动关闭
tl;dr firewall-cmd --permanent --zone=public --add-port=2888/tcp firewall-cmd --reload #重新载入服务 永久配置f ...
- goEasy消息推送,pushlet 向特写用户实时推送
goEasy 1先去goEasy官网注册goeasy.io,并创建application,得到superKey 2引入js <script type="text/javascript& ...
- Hibernate criteria 增加排序项
- C#程序员经常用到的10个实用代码片段
1 读取操作系统和CLR的版本 OperatingSystem os = System.Environment.OSVersion; Console.WriteLine(“Platform: {}”, ...
- 前端开发神器sublime Text
实用的sublime插件集合 – sublime必备插件 前言 入前端领域开始,就学着使用sublime,一直用起来很顺手,速度是我最欣赏的,快的没有编辑器可以匹敌.还是废话不多扯,入正题.好多有多少 ...