文章来源:http://blog.csdn.net/tengdazhang770960436/article/details/48395885

1.SpringMVC 的配置分为两部分 application.xml 和 spring-servlet.xml

2.两个配置文件的作用和配置位置

2.1.application.xml :对应的是系统级别的配置,作用范围是系统上下文。

2.2.spring-servlet.xml:对应的是 controller 级别的配置,作用范围是控制层上下文。

3.它们在web.xml 中的配置

3.1.因为 application.xml 是系统级别的上下文,所以它的初始化需要放到 web.xml 中的<context-param>标签中,同时其他的类似定时任务的配置文件等等都是放在这个标签下进行初始化的。

3.2.因为spring-servlet.xml只是 controller 级别的上下文,说白了就是 servlet 级别的初始化,它不涉及到除了转发之外的任何实体,所以它的作用范围仅仅限制在 servlet 级别,所以它的初始化应该是跟spring 的 DispatcherServlet 初始化在一起,所以就是在 <servlet> 表情中初始化的。它有一个默认值就是【/WEB-INF/remoting-servlet.xml 】,注意配置文件的对应的名称是【 servlet-name】-servlet.xml,所以如果你没有给servlet 制定配置文件的位置,并且在默认位置下也没有配置文件,那么系统启动的时候就会报错。

注意:对于 servlet配置文件里面应该初始化的东西,除了视图的解析方式、静态资源文件的存放位置、controller的初始化方式之外,其他的都不应该放在 servlet 配置文件中,应为它只负责 请求的转发,返回结果的解析以及静态资源文件的解析,其他的对象的初始化,定时任务...都不应该放到这个配置文件下进行管理。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true"> <!-- 这个地方默认加载的是系统的变量的配置文件,它们属于是系统级别的配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/application.xml.xml,
classpath:spring/spring-quartz.xml
</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>
<!-- <context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>classpath:conf/logback.xml</param-value>
</context-param> -->
<!-- <listener>
<listener-class>xorg.springframework.web.util.LogbackConfigListener</listener-class>
</listener> -->
<listener>
<listener-class>com.cloudFarmHDAPI.admin.listener.SystemListener</listener-class>
</listener> <!-- 这个地方加载的是 servlet 的变量的配置文件,它们属于 controller 级别的配置
.如果不配置这个 servlet-context.xml 的配置文件位置,
那么默认就会去/WEB-INF/servlet-context.xml 下面去寻找这个文件
.如果配置了这个位置,那么它就会去制定位置加载文件
-->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/servlet-context.xml</param-value>
</init-param>
<load-on-startup></load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- charactor encoding -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- shiro security filter -->
<filter>
<filter-name>shiroSecurityFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

Springmvc配置文件application.xml 和 spring-servlet.xml的更多相关文章

  1. Spring,SpringMvc配置常见的坑,注解的使用注意事项,applicationContext.xml和spring.mvc.xml配置注意事项,spring中的事务失效,事务不回滚原因

    1.Spring中的applicationContext.xml配置错误导致的异常 异常信息: org.apache.ibatis.binding.BindingException: Invalid ...

  2. springmvc配置文件web.xml详解各方总结(转载)

    Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xm ...

  3. springmvc配置文件web.xml详解各方总结。

    Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xm ...

  4. spring读取xml配置文件(二)

    一.当spring解析完配置文件名的占位符后,就开始refresh容器 @Override public void refresh() throws BeansException, IllegalSt ...

  5. 【转载】SpringMVC配置文件详解

    转自:https://my.oschina.net/happyBKs/blog/691502 web.xml文件是web应用的部署描述. 在上一节的springMVC示例中 ,idea下的Maven- ...

  6. SpringBoot配置文件 application.properties,yaml配置

    SpringBoot配置文件 application.properties,yaml配置 1.Spring Boot 的配置文件 application.properties 1.1 位置问题 1.2 ...

  7. SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-002- 在xml中引用Java配置文件,声明DispatcherServlet、ContextLoaderListener

    一.所有声明都用xml 1. <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  8. springMVC配置文件web.xml与spring-servlet.xml与spring-jdbc.xml与logback.xml与redis.properties与pom.xml

    springMVC注解:@Controller @Service @Repository 分别标注于web层,service层,dao层. web.xml <?xml version=" ...

  9. SpringMVC配置文件-web.xml的配置

    SpringMVC配置文件(重点) @Web.xml @核心拦截器(必配) <!-- spring 核心转发器,拦截指定目录下的请求,分配到配置的拦截路径下处理 --> <servl ...

随机推荐

  1. datatable编辑一行数据的方法

    let d =t.row($(e).parents("tr")).data(); 上面的是获取一行数据的方法,如果是更改一行数据,则传入根之前数据结构相同的对象或者数组即可: t. ...

  2. vue给input file绑定函数获取当前上传的对象

    HTML <input type="file" @change="tirggerFile($event)"> JS(vue-methods) tir ...

  3. Lua常用时间函数

    常用时间函数 print(os.time()) --当前系统时间值 print(os.date( print(os.date("*t"), os.time()) --当前系统时间表 ...

  4. 远程执行命令和文件分发shell脚本

    deploy.conf node01,all,other,datanode,journalnode,zookeeper, node02,all,other,datanode,journalnode,z ...

  5. Windows 安装 adt-bundle的方法

    Refer:http://my.eoe.cn/shuhai/archive/19381.html Windows 安装 adt-bundle的方法 很多大神说Windows下Eclipse启动不起来, ...

  6. Visual Studio 2012中使用GitHub

    前言 一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等 一系列工具进行Copy,然后回家才能继续在原来的基础上作业 ...

  7. 兼容 iOS Retina(视网膜显示) 的程序

    首先我们需要明确一点,iOS设备上图片兼容retina的问题最初是由于iPhone4的分辨率由iPhone3的320X480提升到了640X960所产生. 为了让iPhone4能够兼容iPhone3上 ...

  8. Git Step by Step – (8) Git的merge和rebase

    前面一篇文章中提到了"git pull"等价于"git fetch"加上"git merge",然后还提到了pull命令支持rebase模式 ...

  9. swift开发之--代理协议的使用

    swift代理的使用,和oc版本有区别,区别还是蛮大的,不过和oc一样都是用于反向传值: 实现如下: 1,声明两个类 2,实现流程,viewcontroller页面点击按钮进入firstVC页面,然后 ...

  10. Lua协程-测试3

    print("Lua 协程测试3") -- 实现消费者-生产者关系(生产一个就消费一个) count = -- 生产总数 -- 生产者 local newProductorCo = ...