web.xml配置DispatcherServlet (***-servlert.xml)
1. org.springframework.web.servlet.DispatcherServlet
所在jar包:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
默认配置文件:
DispatcherServlet.properties
上下文:
该DispatcherServlet默认使用WebApplicationContext作为上下文。
2. DispatcherServlet的作用:
DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,主要负责流程的控制。
对应的是 controller 级别的配置,作用范围是控制层上下文。
3. DispatcherServlet怎么配置
servlet-name :随便取。这里配置成[test]。Spring默认配置文件为"/WEB-INF/[servlet名字]-servlet.xml"。
load-on-startup : web.xml中可配置多个servlet。 load-on-startup可指定在系统启动时按顺序加载servlet。
url-pattern :表示哪些请求交给Spring Web MVC处理。此处会处理所有URI为"appName/test/*"的请求。
<!--Spring view分发器-->
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/*</url-pattern>
</servlet-mapping>
4. [servlet名字]-servlet.xml里面的配置
4.1 mvc:annotation-driven
<mvc:annotation-driven />
为什么要配置annotation-driven:
<mvc:annotation-driven />注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例。
如果没有<mvc:annotation-driven/>,那么所有的Controller可能就没有解析。
4.2 context:component-scan
<context:component-scan base-package="com.test.web.controller" />
context:component-scan又干了啥:
a). 有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
b). <context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
c). spring会自动去扫描base-package下面或者子包下面的Java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean。
4.3 mvc:interceptors
<mvc:interceptors>
<bean class="com.test.web.MyInteceptor" />
</mvc:interceptors>
拦截器,拦截所有url。
心血来潮,稍微研究了一下DispatcherServlet。所知有限,这里就不介绍更多。
以下为所有参考的文章:
第三章 DispatcherServlet详解 ——跟开涛学SpringMVC
http://jinnianshilongnian.iteye.com/blog/1602617
web.xml配置文件中的servlet和servlet-mapping
http://blog.csdn.net/u013815649/article/details/50435819
使用@Controller注解为什么要配置<mvc:annotation-driven />
http://blog.csdn.net/jbgtwang/article/details/7359592
spring mvc拦截器和<mvc:annotation-driven />的详解
http://www.cnblogs.com/yangzhilong/p/3725849.html
Spring组件扫描<context:component-scan/>使用详解
http://www.cnblogs.com/maybo/p/5189516.html
<context:component-scan>使用说明
http://blog.csdn.net/chunqiuwei/article/details/16115135
Spring MVC 教程,快速入门,深入分析(推荐阅读)
http://elf8848.iteye.com/blog/875830
web.xml配置DispatcherServlet (***-servlert.xml)的更多相关文章
- 在web.config配置中添加xml内容
在web.config 中添加需要的内容时, 就是在<configuration>节点内添加一个新的<configSections>元素, 在configSections元素中 ...
- SpringMVC、SpringMVC XML配置(纯XML方式)
1.引入SrpingMVC所使用的Java包: cglib-nodep-2.1_3.jar.commons-logging.jar.spring-aspects-4.1.7.RELEASE.jar.s ...
- 02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置
项目结构(所需jar包,配置文件) sqlMapConfig.xml的配置内容如下: <?xmlversion="1.0"encoding="UTF-8&qu ...
- web.xml配置DispatcherServlet
1. org.springframework.web.servlet.DispatcherServlet 所在jar包: <dependency> <groupId>org.s ...
- 2.6.1 XML配置:创建XML文件
(1) 工程名右击---New--file -- newfile窗口中:filename中输入testng.xml testng.xml 文件中打开后,切换到source 标签中.进行编辑. 内容 ...
- Spring MVC Web.xml配置
Web.xml spring&spring mvc 在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个 ...
- springmvc学习指南 之---第27篇 spring如何实现servlet3.0无web.xml 配置servlet对象的
writedby 张艳涛 基于web.xml配置,有人说麻烦,tomcat给按照servlet3.0,实现了基于注解@WebServlet,有人说springmvc的springmvc.xml配置麻烦 ...
- SpringBoot零XML配置的Spring Boot Application
Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...
- 02_Spring Bean的装配模式_基于XML配置方式
一.三种实例化Bean的方式 1.使用类构造器实例化(默认无参数) <bean id="bean1" class="com.demo1.Bean1"> ...
随机推荐
- c# 以换行(\r\n)拆分字符串
c# 以换行(\r\n)拆分字符串 字符串数组形式: string[] striparr = strip.Split(new string[] { "\r\n" }, String ...
- 普通socket与netty服务端交互
Socket socket = new Socket(host, port);OutputStream out = socket.getOutputStream();ByteBuffer header ...
- RxJava2 源码解析(二)
概述 承接上一篇RxJava2 源码解析(一),本系列我们的目的: 知道源头(Observable)是如何将数据发送出去的. 知道终点(Observer)是如何接收到数据的. 何时将源头和 ...
- 4、搭建Python环境
搭建Python环境 Linux环境 大多Linux发行版均默认安装了Pthon环境.如想下载不同的版本,可到www.python.org下载.软件安装方法参照Linux软件安装. 输入Python可 ...
- python 进程池pool简单使用
平常会经常用到多进程,可以用进程池pool来进行自动控制进程,下面介绍一下pool的简单使用. 需要主动是,在Windows上要想使用进程模块,就必须把有关进程的代码写if __name__ == ‘ ...
- Linux 安装 yum
1.使用RedHat系统不能正常使用yum安装 由于RedHat没有注册,所有不能使用它自身的资源更新, 查看安装源是否安装: # rpm –qa|grep yum 卸载安装源: # rpm –e – ...
- phpbbchina恢复上线
上个月已经把ICP备案重新办过了, 但是一直在忙着应付工作上的事. 从上周末开始经过数天的努力, 将 phpbbchina 恢复上线了. 时间一晃, 正好十年. 目前能找到的最新的数据是2008-10 ...
- (原)MobileNetV1
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9410540.html 论文: MobileNets: Efficient Convolutional ...
- 12C -- ORA-01017
本地使用使用sqlplus,尝试连接12.2数据库报错: 在另外一台服务器上,使用sqlplus连接该库,可以成功: 解决方案: 根据MOS文档id:207303.1看出,只有11.2.0.3之上的客 ...
- 【转载】C# Graphics类具体解释
封装一个 GDI+ 画图图面. 此类不能被继承.System.Drawing 命名空间 名称 说明 Clip 获取或设置 Region.该对象限定此 Graphics 的画图区域. ClipBoun ...