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"> ...
随机推荐
- Django缓存1
1. 开发调试 # 此为开始调试用,实际内部不做任何操作 # 配置: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.du ...
- [java]struts2入门
摘要 本文是struts2入门,配置教程.如何在IntelJ Idea中进行手动配置.在使用idea新建struts2web项目的时候,在下载jar包的过程中,下载失败,没办法就直接手动进行下载jar ...
- android:NinePatch图片制作
一.工具介绍 这是一张PNG图片,为了方便观看做的比较大.在Android中使用NinePatch图片的一般都是很小的图片,因为当内容多了的时候,背景会自动拉伸来适应内容,而如果图片做大了,内容少,则 ...
- Unity3D MonoBehaviour的生命周期(lifecycle)
官方的事件函数的执行顺序中有详解(Link:Execution Order of Event Functions) (图片来源:http://whatiseeinit.blogspot.com/201 ...
- PHP内置的预定义常量大全
URL:http://www.php.net/manual/en/reserved.constants.php 预定义常量:核心预定义常量,标准预定义常量----------------------- ...
- JavaScript 编码规范(中文/Airbnb公司版)
Airbnb 是一家位于美国旧金山的公司,本文是其内部的 JavaScript编码规范,写得比较全面,在 Github 上有 16,686 + Star,3,080 + fork,前端开发人员可参考. ...
- SDUT 3002-素数间隙(素数筛+暴力)
素数间隙 Time Limit: 1000ms Memory limit: 262144K 有疑问?点这里^_^ 题目描写叙述 Neko猫是一个非常喜欢玩数字游戏的会说话的肥猫,常常会想到非常多 ...
- awesomes前端资源库网站
https://www.awesomes.cn http://www.cnblogs.com/jiujiaoyangkang/p/4998518.html (web app自适应框架flexible) ...
- 1209 -The MySQL server is running with the --read-only option
1209 - The MySQL server is running with the --read-only option so it cannot execute this statement ...
- Spring Boot 2.0 整合Thymeleaf 模板引擎
本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...