做了那么久的web项目都没有花心思了充分解下这个文件有什么用,看项目配制是否都差不多呢
========================================================================
本文主要是给自己做个笔记,如果说错了或者写的不好,请多包涵或指正(看了别人参考的文献,,只能把自己写的定义为笔记了)
参考大神博客:
http://blog.csdn.net/netdevgirl/article/details/51483273
http://blog.csdn.net/chyohn/article/details/54925124
http://blog.csdn.net/u012562943/article/details/53301334
web.xml主要是用来初始化web的一些东西,比如定制的spring 容器(准确的说是刷新替换默认的容器),初始化参数等
主要有三个标签(常用) 他们随容器初始化好(仅仅初始化一次),和容器一起销毁(同生共死)
1、servlet; 2、filter; 3、listener; web.xml 的加载顺序是:context- param -> listener -> filter -> servlet
一.第一部分
参考tomcat 启动
https://www.cnblogs.com/goody9807/p/4227296.html
参考servlet 和tomcat的关系
http://blog.csdn.net/snarlfuture/article/details/18473761
关于 introspectorcleanuplistener 是为了解决内存泄漏问题(初始化级别高,公司使用了分布式定时器Quartz)
https://www.cnblogs.com/qiankun-site/p/5886673.htm
http://blog.csdn.net/z69183787/article/details/28402649
日志文件配置初始化:
https://www.cnblogs.com/CloverSH/p/4531492.html
//这边的话初始化有公司特定的需求具体的类源码只是为了得到上下文的容器,目的是获取ioc 注入的bean;
==================================================================================================================
<!-- Web侧登入的配置 -->
<servlet>
<servlet-name>spring-mvc-web-login</servlet-name>
<servlet-class>com.fjhb.surveyor.gateway.interceptor.AllowCrossDomainDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/mvc/spring-mvc-web-login.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc-web-login</servlet-name>
<url-pattern>/web/login/*</url-pattern>
</servlet-mapping>
<!-- Web侧管理端 -->
<servlet>
<servlet-name>spring-mvc-web-admin</servlet-name>
<servlet-class>com.fjhb.surveyor.gateway.interceptor.AllowCrossDomainDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/mvc/spring-mvc-web-admin.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc-web-admin</servlet-name>
<url-pattern>/web/admin/*</url-pattern>
</servlet-mapping>
...
更具不同的请求,初始化配制..登录/未登录,app登录/未登录
=======================================================================================================================
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/web/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/mobile/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
<init-param>
<param-name>exclusions</param-name>
<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
</init-param>
<init-param>
<param-name>sessionStatMaxCount</param-name>
<param-value>5000</param-value>
</init-param>
<init-param>
<param-name>principalSessionName</param-name>
<param-value>USER</param-value>
</init-param>
<init-param>
<param-name>principalCookieName</param-name>
<param-value>uid</param-value>
</init-param>
<init-param>
<param-name>profileEnable</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 数据库连接池监控 -->
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>DruidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
<welcome-file-list>
<!--<welcome-file>/index_student.html</welcome-file>-->
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
阿里巴巴 数据库连接池监控 可以更具配制访问
http://blog.csdn.net/pk490525/article/details/12621649
==========================================================================
我复制了admin的配置
spring-mvc-web-admin.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- spring mvc -->
<context:annotation-config />
<!-- 指定搜索自动装配组件的路径 -->
<context:component-scan base-package="com.fjhb.surveyor.gateway.web.admin" />
<mvc:annotation-driven validator="validator">
<!-- Action参数支持Query特性 -->
<mvc:argument-resolvers>
<bean class="com.fjhb.surveyor.gateway.interceptor.QueryHandlerMethodArgumentResolver"/>
<bean class="com.fjhb.surveyor.gateway.interceptor.BeanPropertyMethodArgumentResolver"/>
</mvc:argument-resolvers>
<!-- 增加使用@ResponseBody进行内容输出字符串时的编码为utf-8,以及如果输出javaBean使用FastJson -->
<mvc:message-converters>
<bean class="com.fjhb.surveyor.gateway.interceptor.WrappedFastJsonHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 全局的拦截器用于响应头增加跨域和编码支持 -->
<mvc:interceptors>
<bean class="com.fjhb.surveyor.gateway.interceptor.UserLoginInterceptor"/>
<bean class="com.fjhb.surveyor.gateway.interceptor.GlobalInterceptor" />
</mvc:interceptors>
<mvc:default-servlet-handler />
<!-- 全局的异常拦截器 -->
<bean class="com.fjhb.surveyor.gateway.interceptor.WrappedHandlerExceptionResolver"/>
<!-- spring mvc的文件上传解析,这里的bean的id必须是multipartResolver否则无法使用MultipartHttpServletRequest -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="defaultMethodKeyGenerator" class="com.fjhb.surveyor.utils.shell.DefaultMethodKeyGenerator"/>
<bean class="com.fjhb.shell.spring.ShellBeanPostProcessor">
<property name="basePackages" value="com.fjhb.sgk"/>
<property name="shellMethodKeyGenerator" ref="defaultMethodKeyGenerator"/>
</bean>
</beans>
主要是想搞清楚怎么拦截全局异常,以及全局返回值的格式