Spring简单部署

mark

<?xml version="1.0" encoding="UTF-8"?>
<web-app
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID"
	version="2.5">
	<display-name>spring_game</display-name>
        <!-- 预加载的spring bean (context-param 配置XML)-->
	<listener>
	    <listener-class>
org.springframework.web.context.ContextLoaderListener
            </listener-class>
	</listener>
    <context-param>
	    <param-name>contextConfigLocation</param-name>
	        <param-value>
		    /WEB-INF/config/ContextLoaderListener.xml
		    /WEB-INF/config/quartz-task.xml
	    </param-value>
	</context-param>

	<!-- POST中文乱码过滤器 -->
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
    <!-- 使用 DispatcherServlet 来做分发 -->
	<servlet>
		<servlet-name>spring_game</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
            <!-- 将对应的分发ActionServlet的配置,在默认的情况下,是使用[servlet-name]-servlet.xml文件 -->
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/config/jm_admin_servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring_game</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<!-- 单独定义Servlet出去 -->
	<!-- 
            <servlet> 
                <servlet-name>ActionServlet</servlet-name> 
                <servlet-class>
                      com.jm.admin.pro.action.ActionServlet
                </servlet-class> 
	    </servlet> 
            <servlet-mapping> 
                <servlet-name>ActionServlet</servlet-name> 
                <url-pattern>/action.do</url-pattern> 
            </servlet-mapping>
         -->
</web-app>

DispatcherServlet与ContextLoaderListener的区别:

DispatcherServlet中加载的配置文件的作用域是在web请求的时候才触发的,一般跟controller相关的bean配置会放在这里面,例如视图解析器的bean,而ContextLoaderListener加载的配置文件的作用域是在整个环境中,类似于application级别的,一般在这个配置文件中定义的是公共的内容,例如db、service等等。

相关推荐