<?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:tx="http://www.springframework.org/schema/tx"
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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 自己主动扫描的包名 -->
<context:component-scan base-package="com.app,com.core,JUnit4" ></context:component-scan> <!-- 默认的注解映射的支持 -->
<mvc:annotation-driven /> <!-- 视图解释类 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/><!--可为空,方便实现自已的根据扩展名来选择视图解释类的逻辑 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean> <!-- 拦截器 -->
<mvc:interceptors>
<bean class="com.core.mvc.MyInteceptor" />
</mvc:interceptors> <!-- 对静态资源文件的訪问 方案一 (二选一) -->
<mvc:default-servlet-handler/> <!-- 对静态资源文件的訪问 方案二 (二选一)-->
<mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
<mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>
<mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/> </beans>

<context:component-scan/> 扫描指定的包中的类上的注解。经常使用的注解有:

@Controller 声明Action组件

@Service    声明Service组件    @Service("myMovieLister") 

@Repository 声明Dao组件

@Component   泛指组件, 当不好归类时. 

@RequestMapping("/menu")  请求映射

@Resource  用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName") 

@Autowired 用于注入。(srping提供的) 默认按类型装配 

@Transactional( rollbackFor={Exception.class}) 事务管理

@ResponseBody 该注解用于读取Request请求的body部分数据。使用系统默认配置的HttpMessageConverter进行解析,然后把对应的数据绑定到要返回的对象上。

@Scope("prototype")   设定bean的作用域

<mvc:annotation-driven /> 是一种简写形式。全然能够手动配置替代这样的简写形式。简写形式能够让初学都高速应用默认配置方案。

<mvc:annotation-driven /> 会自己主动注冊DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。

并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持。@Valid支持,读写XML的支持(JAXB),读写JSON的支。

我们处理响应ajax请求时,就使用到了对json的支持。

对action写JUnit单元測试时。要从spring IOC容器中取DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,来完毕測试,取的时候要知道是<mvc:annotation-driven />这一句注冊的这两个bean。

<mvc:interceptors/> 是一种简写形式。通过看前面的大图,知道,我们能够配置多个HandlerMapping。

<mvc:interceptors/>会为每个HandlerMapping。注入一个拦截器。事实上我们也能够手动配置为每个HandlerMapping注入一个拦截器。

<mvc:default-servlet-handler/> 使用默认的Servlet来响应静态文件。

<mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/> 匹配URL  /images/**  的URL被当做静态资源,由Spring读出到内存中再响应http

springMVC --DispatcherServlet具体解释

springMVC --配置具体与注讲解明的更多相关文章

  1. Spring-MVC配置Gson做为Message Converter解析Json

    Spring-MVC配置Gson做为Message Converter解析Json 在学习Spring的时候看到可以使用@RequestBody 和@ResponseBody注解来是的Spring自动 ...

  2. SpringMVC配置实例

    一.SpringMVC概述 MVCII模式实现的框架技术 Model--业务模型(Biz,Dao...) View--jsp及相关的jquery框架技术(easyui) Contraller--Dis ...

  3. SpringMVC配置与使用

    一.MVC概要 MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范,用一种将业务逻辑.数据.显示分离的方法组织代码,MVC主要作用是降低了视图与业务 ...

  4. 3.2.2 SpringMVC配置式开发

    SpringMVC配置式开发 1. SpringMVC运行原理(执行过程) 2. 需求 用户提交一个请求, 服务端处理器接收到请求后, 给出一条信息,在相应页面中显示该条信息 3. 开发步骤 (1) ...

  5. springmvc配置之mvc:annotation-driven

    为了简化springmvc配置,spring同时引入了mvc namespace, 配置了 <mvc:annotation-driven/> spring会默认注册a RequestMap ...

  6. SpringMVC配置多视图-内容协商原理

    SpringMVC配置多视图-内容协商原理 2014年03月06日 16:46:59 日积月累_滴水石穿 阅读数:10964更多 个人分类: SpringMVC   Spring Framework ...

  7. 马士兵hadoop第四课:Yarn和Map/Reduce配置启动和原理讲解

    马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...

  8. Spring实战第七章————SpringMVC配置的替代方案

    SpringMVC配置的替代方案 自定义DispatherServlet配置 我们之前在SpittrWebAppInitializer所编写的三个方法仅仅是必须要重载的abstract方法.但还有更多 ...

  9. 马士兵hadoop第四课:Yarn和Map/Reduce配置启动和原理讲解(转)

    马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...

随机推荐

  1. Spring Cloud 目录

    Spring Cloud Eureka Spring Cloud Config Spring Cloud Feign Spring Cloud Hystrix Spring Cloud Ribbon ...

  2. idea热部署设置(复制)

    提出问题 IntelliJ IDEA工具如何设置热部署??? 解决问题 我的IDEA的版本是:IntelliJ IDEA 14.0.2 第一步:打开tomcat配置 这里写图片描述 第二步: 这里写图 ...

  3. struts OGNL详解

    首先了解下OGNL的概念: OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的 ...

  4. jquery版右下角弹窗效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  5. Weixin API -- 微信js接口

    今天在开发项目的时候,由于需要在微信中实现分享功能(分享成功后实现页面跳转并记录).问度娘,找了很久,终于找到一个不错的方法.收藏起来以后备用,也希望对大家有所帮助! 在github的地址:https ...

  6. POJ 2104:K-th Number(主席树静态区间k大)

    题目大意:对于一个序列,每次询问区间[l,r]的第k大树. 分析: 主席树模板题 program kthtree; type point=record l,r,s:longint; end; var ...

  7. css 三列布局

    前面的话 前面已经介绍过单列定宽单列自适应和两列自适应的两列布局.本文介绍三列布局,分为两侧定宽中间自适应.两列定宽一侧自适应.中间定宽两侧自适应.一侧定宽两列自适应和三列自适应这五种情况 两侧定宽中 ...

  8. 洛谷 [P3381] 最小费用最大流模版

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  9. hash function 字符串哈希函数

    #include <stdio.h> int hash(const char *str) { ; ;;i++) { if (str[i] == '\0') break; sum += (( ...

  10. linux下的用户管理(二)

    创建帐号: 手工创建-> 1.在/etc/passwd中添加一条记录 2.创建用户主目录 3.在用户的家目录下设置默认的配置文件 4.设置用户初始口令 命令创建-> useradd或add ...