Spring配置文件-笔记

启动服务器:
    <!-- Spring ApplicationContext配置文件的路径,可使用通配符. -->
    <!-- 多个路径用,号分隔此参数用于后面的Spring Context Loader -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/applicationContext.xml</param-value>
    </context-param>
    <!-- Spring初始化容器类. -->
    <!-- 取配置文件里面定义的参数contextConfigLocation-->
    <!-- 若没有定义参数,则默认读取applicationContext.xml. -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
以上内容会初始化容器类,实例化所有交给Spring的类。

用户请求过滤类:
   <!-- 字符编码过滤. -->
    <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-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
用户请求分发类: <!-- Spring分发的类,所有以.html结尾的页面均对应classpath*:dispatcher-servlet.xml配置文件. --> <servlet> <servlet-name>dispatcher-servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher-servlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> 其他辅助类: <!-- Spring 刷新Introspector防止内存泄露 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- spring Security获得session生存周期事件 --> <listener> <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher </listener-class> </listener>

  

posted @ 2012-09-18 14:30  我是小菜鸟  阅读(276)  评论(0编辑  收藏  举报