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. react-navigation 使用详解(转载)

    上篇博客和大家分享了关于React Native jsBundle预加载,界面启动优化的内容,详情可点击: 基于最新版本React Native实现JsBundle预加载,界面秒开优化 一.开源库介绍 ...

  2. pdb的数量限制

    Decide How to Configure the CDB --搜索文档 Prepare to create the CDB by research and careful planning. T ...

  3. Ubuntu16.04安装OpenCV3.2以及PCL1.8

    最近在学习slam14讲,需要配置一些环境<视觉slam十四讲> 这本书中已经给出如何配置相关环境的比较详细的说明,但是有些环境并无卵用,比如OpenCV以及PCL 这里给出自己屡试不爽的 ...

  4. 九度OJ-1001-A+B矩阵-有些小技巧

    题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:22974 解决:9099 题目描述: This time, you are supposed ...

  5. Angular 手动解析表达式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. Unity 3D-AR开发-Vuforia教程手册

    Unity 开发AR之 Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar - ...

  7. lesson1-fastai

    fast-ai系统资料https://www.jianshu.com/p/2fe22a6b0ecb 中文视频 https://www.bilibili.com/video/av10156946/ind ...

  8. error: ld returned 1 exit status 解决

    1.程序未结束运行 2.全局变量冲突,不是宏定义冲突

  9. 2017.4.5 Strom

    Strom是分布式实时计算系统,它对于实时计算的意义类似于hadoop对于批处理的意义.与Storm关系密切的语言:核心代码用clojure书写,实用程序用python开发,使用java开发拓扑. S ...

  10. 转载《Oracle的tnsnames.ora配置(PLSQL Developer)》

    源地址:https://www.cnblogs.com/qq3245792286/p/6212617.html. 首先打开tnsnames.ora的存放目录,一般为D:\app\Administrat ...