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"> ...
随机推荐
- 关于数据库alter的一系列操作总结
表操作 对于表的操作——创建(create),删除(drop)来说,基本上大家都很清楚,而作为很少被使用到的修改(alter)命令往往存在一些问题,现在做一下总结: 添加列:alter table 表 ...
- mongodb group操作 以及管道 aggregate 分组排序分页
分组获取数据: db.express_info.group({ "key":{"express_code":true}, "initial" ...
- innodb文件
参数文件 日志文件 socket文件 pid文件 mysql表结构文件 存储引擎文件 1. 错误日志 启用错误日志方法 /etc/init.d/mysql启动文件中 /usr/bin/mysqld_s ...
- Linux及MacOSX中使用zsh
via : http://leochin.com/linux-macosx-shell-zsh/ Linux及MacOSX中使用zsh zsh是另一种Shell,类似bash,tcsh等等,只是多了一 ...
- EF6 简单增删改查示例代码
示例一: private DbContext _dbContext; public DbContext CurrentContext { get { if (_dbContext == null) { ...
- linux-批量杀死进程
kill `ps -ef|grep 进程名 | grep -v grep|awk '{print $2}'` 例如: kill `ps -ef | grep /etc/pam.d/su |grep - ...
- mipmap和drawable文件夹的区别
在Android上创建工程,会默认创建mipmap文件夹.之前在Eclipse上创建的是drawable的文件夹.那么这两个有什么区别呢? 问题: I'm working with android s ...
- GitHub下载安装以及开源项目
Git for Windows安装与使用 http://cioworld.org/freedom/content/git-windows 下载Git-1.8.3-preview20130601.exe ...
- javascript中return function与return function()的区别
参考https://stackoverflow.com/questions/7629891/functions-that-return-a-function-javascript 问题:唯一的区别是r ...
- springboot本地读取resources/images没问题,上传到云服务器打成jar包就读取不到问题
//String watermarkfileName = this.getClass().getClassLoader().getResource("images/watermark.png ...