学SpringMVC收藏

学SpringMVC收藏 一个较完整的SpringMVC工程的配置

2014-01-22 17:17:25

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://flyingsnail.blog.51cto.com/5341669/1353894

一、

在本人的《web.xml加载顺序》文章中介绍到了,在web.xml中配置的加载顺序为:

ServletContext-> context-param ->listener -> filter -> servlet

本文就结合该加载顺序,详细的介绍一个较完整的工程的配置。

二、

该较完整的工程应该包括:

1、应用Spring;

2、应用SpringMVC;

3、实现SpringSecurity来实现权限管理和身份验证;

4、JVM加载工程时,实现配置信息初始化(读取xml文件、类文件的注解信息等)。

三、

完整的web.xml文件描述:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <display-name>securityTest</display-name>
    <description>security application test</description>
                                                                                                                                                                                   
    <context-param>
        <param-name>projectCode</param-name>
        <param-value>securityTest</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
            classpath:applicationContext-security.xml
        </param-value>
    </context-param>
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <display-name>Character Encoding Filter</display-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>
    <!-- Use Spring's encoding filter -->
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <!--filter-name>encodingFilter</filter-name-->
        <url-pattern>/*</url-pattern>
    </filter-mapping>
                                                                                                                                                                                   
    <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>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>security</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:mvc-config.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>security</servlet-name>
        <url-pattern>*.s</url-pattern>
    </servlet-mapping>
                                                                                                                                                                                   
    <servlet>
        <servlet-name>securityTestInitialServlet</servlet-name>
        <servlet-class>
           com.yc.securityTest.web.SecurityTestInitialServlet
        </servlet-class>
        <load-on-startup>10</load-on-startup>
        <init-param>
            <param-name>flag</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>
                                                                                                                                                                                   
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
                                                                                                                                                                                   
</web-app>

根据web.xml文件加载配置的顺序,可以把上面的配置详细描述为:

学SpringMVC收藏

四、

对应于springMVC的搭建和配置可参考:

《SpringMVC常用基础知识【转】》

《Spring MVC 框架搭建及详解》

SpringMVC入门实例及详细讲解

《跟开涛学SpringMVC》

基于注解的 Spring MVC 简单入门

《Spring MVC全部文档》

Spring MVC 教程,快速入门,深入分析

对应于springSecurity的搭建及配置可参考:

spring-security3 配置和使用

《Spring Security3.1 最新配置实例》

《Spring Security学习总结》

SpringSecurity3配置及原理简介

springSecurity源码分析——DelegatingFilterProxy类的作用

对应于实现配置信息初始化(读取xml文件、类文件的注解信息等),可参考我的另一篇文章《SpringMVC读取controller信息》

本文出自 “会飞的蜗牛” 博客,请务必保留此出处http://flyingsnail.blog.51cto.com/5341669/1353894

上一篇:我是庖丁,<肢解IOT平台>之物模型


下一篇:win7下安装Ubuntukylin-14.04双系统