SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
Spring-servlet.xml
- <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的作用域 - <mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
- 视图解析类,使用普通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> - 添加静态资源访问的支持:
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>

SpringMVC-DispatcherServlet配置(Spring-servlet.xml)的更多相关文章
- eclipse快速配置spring相关xml文件头信息
通过spring tools 插件工具来快速配置xml头信息 ctrl +n 创建-----------> 输入spring 选中spring Beann Configuration File ...
- 在IDEA中配置Spring的XML装配
不考虑混合模式的话,Spring有三类装配Bean的方法,自动装配和Java代码装配都会很容易上手,但在弄XML装配时遇到了问题,这与IDEA环境有关. 装配时需要在源码中配置XML文件的位置,我看别 ...
- 如何配置Spring的XML文件及使用
App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> & ...
- SpringMVC 零配置 无web.xml
对SpringMVC启动流程的讲解 https://www.cnblogs.com/beiyan/p/5942741.html 与SpringMVC的整合 https://hanqunfeng.ite ...
- SSM Spring +SpringMVC+Mybatis 整合配置 及pom.xml
SSM Spring +SpringMVC+Mybatis 配置 及pom.xml SSM框架(spring+springMVC+Mybatis) pom.xml文件 maven下的ssm整合配置步骤
- 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章—SpringMVC高级技术—不用web.xml,而使用java类配置SpringMVC
不用web.xml,而使用java类配置SpringMVC DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置 ...
- springMVC基础配置
web.xml文件 <?xml version="1.0" encoding="UTF-8"?><web-app version= ...
- Spring 快速开始 配置Spring Framework
[配置Spring Framework] 1.XML配置依赖关系 bean是由Springframework管理,我们自己编写bean,Spring也内建了bean,比如ApplicationCont ...
- Spring、Springmvc整合web的web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...
随机推荐
- elasticsearch index tuning
一.扩容 tag_server当前使用ElasticSearch版本为5.6,此版本单个index的分片是固定的,一旦创建后不能更改. 1.扩容方法1,不适 ES6.1支持split index功能, ...
- 通过putty进行端口映射并且启动jupyter notebook
通过内网穿透之后,一般而言,我们访问内网中的机器在ubuntu下一句命令: ssh name@阿里云 -p 6000即可进行访问,其中-p是表示端口号:同样的通过windows下的putty也可修改对 ...
- APK模式下,epg版本升级,需要做同步
采用安卓盒子(APK模式),需要在管理节点做一个同步: 同步目录: /var/www/html/upgradestb 从管理节点向三台业务节点同步: 2018/01/19 conf/server.co ...
- display: table; 100%的宽度
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- [LeetCode&Python] Problem 258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- 使用apidoc 生成Restful web Api文档——新手问题与解决方法
使用apidoc工具来给项目做接口文档,不仅有合理的源码注释,还可以生成对应的文档.是给源码写备注的一个极佳实践. 工具名称:apiDoc Git地址:https://github.com/apido ...
- # 20155219实验二 Java面向对象程序设计
20155219实验二 Java面向对象程序设计 一.实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5 ...
- jquery选择后代以及toggle,toggleClass用法
$("#id").find(".classname") 选择id为xx下的类名为xx的元素 toggle $(this).next(".c ...
- pytonn04day
参考: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions 一列表 它是以[ ]括起来, 每个元素⽤用 ...
- 51Nod 1084:矩阵取数问题 V2(多维DP)
1084 矩阵取数问题 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 一个M*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励 ...