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. Java中的break和continue以及标签

    一.Java中的break,continue,goto 首先break,continue是Java中的关键字,而goto是保留字. 基于goto在c和c++中的鬼畜表现,我觉得goto可能还会长期在J ...

  2. Django中的应用

    1.什么是应用 应用就是网站中的一个独立的程序模块,在Django中,主目录一般不处理具体的请求,主目录一般要处理的是项目的初始化操作以及请求的分发(分布式请求处理).而具体的请求是由各个应用去处理. ...

  3. go服务运行框架go-svc

    go-svc:https://github.com/judwhite/go-svc/svc go-svc支持linux和windows,应用只需实现Service接口即可. 官方例子 package ...

  4. HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)

    pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...

  5. 田螺便利店—PyCharm安装第三方库

    PyCharm安装第三方库是十分方便的,无需pip或其他工具,平台就自带了这个功能而且操作十分简便.如下: 1. 打开软件,点击左上角“文件(File)”—>“设置(setting)”: 2. ...

  6. React两三事

    在setState中改变变量的状态应该用,this .state....而不是 this.props...

  7. Java设计模式(一)

    1.什么是设计模式? 在软件工程中,设计模式是对软件设计中普遍存在的各种问题,所提出的 解决方案. 换句话说,设计模式是一套被反复使用.多数人知晓的.经过分类的.代码设计的 经验的总结.使用设计模式是 ...

  8. 2018.10.25 CCSP马拉松摸铜归来

    24号体测跑50+1000米. 50米抢跑被罚重跑???然后老年人就只能吊着一口仙气跑第二次50米.然后跑1000米,然后再到宿舍收拾行李赶往地铁站,然后再冲到火车站...(卒) 宾馆,三人挤入二人房 ...

  9. 快速排序 C语言实现

    转载于> http://blog.chinaunix.net/uid-26404477-id-3329885.html 总的关键字比较次数:O(nlgn) 尽管快速排序的最坏时间为O(n2),但 ...

  10. mvc core2.1 Identity.EntityFramework Core 用户Claims查看(七)

    添加角色属性查看 Views ->Shared->_Layout.cshtml <div class="navbar-collapse collapse"> ...