spring mvc配置文件简单实现

ContextLoaderListener:Spring MVC在Web容器中的启动类,负责Spring IoC容器在Web上下文中的初始化,使得容器能够自动装配ApplicationContext的配置信息。

在web.xml中配置该类:

<listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener
 </listener-class>
 </listener>

如何部署applicationContext的xml文件,如果在web.xml中不写任何参数配置信息,默认的路径是"/WEB-INF/applicationContext.xml,在WEB-INF目录下创建的xml文件的名称必须是applicationContext.xml。如果是要自定义文件名可以在web.xml里加入contextConfigLocation这个context参数:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/classes/applicationContext-*.xml
        </param-value>
    </context-param>

小结:当在web.xml中配置了listener监视器时,applicationcontext的配置方式有两种。

一是:在web.xml中不作任何配置,此时默认加载/WEB-INF/applicationContext.xml,故必须在/WEB-INF/文件目录下建一个applicationContext.xml文件。

二是:在web.xml中自定义applicationcontext的参数名和位置。

参考:http://my.oschina.net/pkpk1234/blog/61971



在web容器中使用spring mvc框架时,一般必须进行的四项配置修改web.xml,编写servletname-servlet.xml、配置contextConfigLocation初始化参数、配置ContextLoaderListerner。(某些情况下也可以不配置contextConfigLocation初始化参数、ContextLoaderListerner)

时间: 2024-08-04 14:20:19

spring mvc配置文件简单实现的相关文章

用Spring MVC开发简单的Web应用

这个例子是来自于Gary Mak等人写的Spring攻略(第二版)第八章Spring @MVC中的一个例子,在此以学习为目的进行记录. 问题:想用Spring MVC开发一个简单的Web应用, 学习这个框架的基本概念和配置. 解决方案: Spring MVC的核心组件是一个控制器(大多数框架都是控制器比较重要吧). 在最简单的Spring MVC应用中,控制器是需要在web.xml文件中配置的唯一Servlet. Spring MVC的控制器通常称作请求分发Servlet(Dispatcher

spring mvc 配置文件:

标准方法是在web.xml中配置两个,然后在spring mvc配置文件中注解只扫controller注解,其余spring不扫controller注解 一.最开始当然是web.xml文件了,这是一个总的宏观配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee&q

[一站式服务]Spring MVC实现简单CURD项目

前言 一个简单的网页CURD系统,用上了从来没用多的Spring MVC框架,一路走来,收获了很多,在这里记录下来分享给大家! 流程 搭建spring 框架(MVC 上下文.监听器.设置过滤jsp和html.GBK编码.session时间.jsp配置标签)--->JdbcTemplate及数据库配置 --->tomcat部署项目--->编码(pojo.persistence.service.controller.jsp) 学习收获(走过的坑) 1.Tomcat Context配置[2]:

Spring MVC 配置文件 web.xml文件详解

<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.s

Spring MVC 配置文件dispatcher-servlet.xml 文件详解

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/sch

Spring MVC 配置文件dispatcher-servlet.xml 文件详解(转自 学无止境-yj)

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/sch

spring mvc 配置文件拦截器过滤url

最近在用spring mvc拦截器,sprin 版本号4.0.6.RELEASE, <mvc:interceptor> <mvc:mapping path="/admin/**" /> <ref bean="manageInterceptor"/> </mvc:interceptor> 这个mvc:mapping 配置的值是拦截器有效的url匹配  之前/admin/* 这样只会拦截/admin/一级的url, 然后加

spring mvc配置文件

<?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/sch

Spring MVC配置文件解释

<?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/sche