Spring-servlet.xml

  1. <context:component-scan base-package="com.spring.mvc.controller"/>

    扫描指定的包中的类上的注解,常用的注解有:

    @Controller 声明Action组件
    @Service    声明Service组件    @Service("myMovieLister") 
    @Repository 声明Dao组件
    @Component   泛指组件, 当不好归类时. 
    @RequestMapping("/menu")  请求映射
    @Resource  用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName") 
    @Autowired 用于注入,(srping提供的) 默认按类型装配 
    @Transactional( rollbackFor={Exception.class}) 事务管理
    @ResponseBody
    @Scope("prototype")   设定bean的作用域

  2. <mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
  3. 视图解析类,使用普通bean的配置方式:
    1 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    2 <property name="prefix" value="/WEB-INF/views/"></property>
    3 <property name="suffix" value=".jsp"></property>
    4 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    5 </bean>
  4. 添加静态资源访问的支持:
    1 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>

    匹配URL  /resources/**  的URL被当做静态资源,由Spring读出到内存中再响应http。

    或直接使用默认的Servlet来响应静态文件。

    <mvc:default-servlet-handler/>

示例:

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:mvc="http://www.springframework.org/schema/mvc"
5 xmlns:p="http://www.springframework.org/schema/p"
6 xmlns:context="http://www.springframework.org/schema/context"
7 xsi:schemaLocation="
8 http://www.springframework.org/schema/beans
9 http://www.springframework.org/schema/beans/spring-beans.xsd
10 http://www.springframework.org/schema/context
11 http://www.springframework.org/schema/context/spring-context.xsd
12 http://www.springframework.org/schema/mvc
13 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
14 <context:component-scan base-package="com.spring.mvc.controller"/>
15 <mvc:annotation-driven/>
16 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17 <property name="prefix" value="/WEB-INF/views/"></property>
18 <property name="suffix" value=".jsp"></property>
19 </bean>
20 <!--添加访问静态资源的功能 -->
21 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
22 </beans>

God, Grant me the SERENITY, to accept the things I cannot change, COURAGE to change the things I can, and the WISDOM to know the difference.

SpringMVC-DispatcherServlet配置(Spring-servlet.xml)的更多相关文章

  1. eclipse快速配置spring相关xml文件头信息

    通过spring tools 插件工具来快速配置xml头信息 ctrl +n 创建-----------> 输入spring 选中spring Beann Configuration File ...

  2. 在IDEA中配置Spring的XML装配

    不考虑混合模式的话,Spring有三类装配Bean的方法,自动装配和Java代码装配都会很容易上手,但在弄XML装配时遇到了问题,这与IDEA环境有关. 装配时需要在源码中配置XML文件的位置,我看别 ...

  3. 如何配置Spring的XML文件及使用

    App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> & ...

  4. SpringMVC 零配置 无web.xml

    对SpringMVC启动流程的讲解 https://www.cnblogs.com/beiyan/p/5942741.html 与SpringMVC的整合 https://hanqunfeng.ite ...

  5. SSM Spring +SpringMVC+Mybatis 整合配置 及pom.xml

    SSM Spring +SpringMVC+Mybatis 配置 及pom.xml SSM框架(spring+springMVC+Mybatis) pom.xml文件 maven下的ssm整合配置步骤

  6. SpringMVC、SpringMVC XML配置(纯XML方式)

    1.引入SrpingMVC所使用的Java包: cglib-nodep-2.1_3.jar.commons-logging.jar.spring-aspects-4.1.7.RELEASE.jar.s ...

  7. 第7章—SpringMVC高级技术—不用web.xml,而使用java类配置SpringMVC

    不用web.xml,而使用java类配置SpringMVC DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置 ...

  8. springMVC基础配置

    web.xml文件       <?xml version="1.0" encoding="UTF-8"?><web-app version= ...

  9. Spring 快速开始 配置Spring Framework

    [配置Spring Framework] 1.XML配置依赖关系 bean是由Springframework管理,我们自己编写bean,Spring也内建了bean,比如ApplicationCont ...

  10. Spring、Springmvc整合web的web.xml配置

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

随机推荐

  1. Spring Batch 简介

    Spring Batch是一个轻量级的,完全面向Spring的批处理框架,可以应用于企业级大量的数据处理系统.Spring Batch以POJO和大家熟知的Spring框架为基础,使开发者更容易的访问 ...

  2. Python学习笔记第九周

    目录: 一.基础概念 1.paramiko模块 2.进程与线程 1.进程 2.线程 3.进程与线程的区别 4.Python GIL 5.thread模块 6.Join与Daemon 7.线程锁(Mut ...

  3. requestAnimationFrame结束demo

  4. HDU - 5157 :Harry and magic string (回文树,求多少对不相交的回文串)

    Sample Input aca aaaa Sample Output 3 15 题意: 多组输入,每次给定字符串S(|S|<1e5),求多少对不相交的回文串. 思路:可以用回文树求出以每个位置 ...

  5. Arcgis API for JS——打印控件乱码

    在通过Arcgis API for JS编写打印控件进行地图下载时,总发现地图字体乱码,如下图: 解决方法: 在装有ArcGIS Server,要调用服务的电脑或服务器上找到下图文件夹

  6. C语言--第四周作业评分和总结(5班)

    作业链接:https://edu.cnblogs.com/campus/hljkj/CS2017-5/homework/1129 一.评分要求 要求1 完成PTA第四周所有题(20分). 要求2 4道 ...

  7. NET Core 实战 Dapper 扩展数据访问

    NET Core 实战:基于 Dapper 扩展你的数据访问方法 一.前言 在非静态页面的项目开发中,必定会涉及到对于数据库的访问,最开始呢,我们使用 Ado.Net,通过编写 SQL 帮助类帮我们实 ...

  8. Python的文件处理

    引子 1.问题:给你一个文件 "兼职白领学生空姐模特护士联系方式.txt" ,如何查看内容? 答: 安装文本编辑器软件 选中右键,利用文本编辑器软件打开 查看 or 写入 保存,关 ...

  9. 【mysql】索引原理-MySQL索引原理以及查询优化

    转载:https://www.cnblogs.com/bypp/p/7755307.html 一.介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性 ...

  10. linux 条件

    1.文件状态测试-d 目录 -r 可读-f 常规文件 -w 可写-L 符号连接 -x 可执行-s 文件长度大于0,非空 -u 文件有suid位设置 示例: [ -s haison.c ] 0表示成功, ...