【Spring】SpringMVC配置文件
SpringMVC中一般会引入三个配置文件applicationContext.xml、dispatcher-servlet.xml(SpringMVC-servlet.xml)、web.xml
1.dispatcher-servlet.xml(SpringMVC-servlet.xml)
DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,默认使用servlet context。加载包含Web组件的bean,如控制器、视图解析器以及处理器映射。
mvc:annotation-driven
当配置了mvc:annotation-driven/后,Spring就知道了我们启用注解驱动。然后Spring通过context:component-scan/标签的配置,会自动为我们将扫描到的@Component,@Controller,@Service,@Repository等注解标记的组件注册到工厂中,来处理我们的请求。配置如果没有mvc:annotation-driven/,那么所有的Controller可能就没有解析。
context:component-scan
<!-- 扫描controller -->
<context:component-scan base-package="**.*controller"/>
2.applicationContext.xml
使用application context,使用SpringMVC可以不配置applicationContext.xml,若使用需要在web.xml中添加Listener。加载应用中的其他bean,通常是驱动应用后端的中间层和数据层组件。
<!-- 默认的spring配置文件是在WEB-INF下的applicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext*.xml
</param-value>
</context-param>
3.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- 默认的spring配置文件是在WEB-INF下的applicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext*.xml
</param-value>
</context-param>
<!-- springMVC的核心控制器 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:springMVC-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
【Spring】SpringMVC配置文件的更多相关文章
- shiro学习(四、shiro集成spring+springmvc)
依赖:spring-context,spring-MVC,shiro-core,shiro-spring,shiro-web 实话实说:web.xml,spring,springmvc配置文件好难 大 ...
- Spring+SpringMVC+Mybaties整合之配置文件如何配置及内容解释--可直接拷贝使用--不定时更改之2017/4/27
以下配置可直接使用,只需更改包名. 关于内部标签的解释及用法,都以注解形式在代码内部说明.个人原创,转载需注明出处. 1,web.xml.添加jar包后首先需要配置WEB-INF下的web.xml文件 ...
- Spring+SpringMVC+MyBatis深入学习及搭建(三)——MyBatis全局配置文件解析
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6874672.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(二)——My ...
- spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件
这篇文章用来总结一下spring,springmvc,spring+mybatis,spring+hibernate的配置文件 1.web.xml 要使用spring,必须在web.xml中定义分发器 ...
- Spring+SpringMVC重复加载配置文件问题
sping+springmvc的框架中,IOC容器的加载过程 http://my.oschina.net/xianggao/blog/596476 基本上是先加载ContextLoaderListen ...
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释(转)
原文:https://blog.csdn.net/yijiemamin/article/details/51156189# 这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文 ...
- 0927-转载:SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
这篇文章暂时只对框架中所要用到的配置文件进行解释说明,而且是针对注解形式的,框架运转的具体流程过两天再进行总结. spring+springmvc+mybatis框架中用到了三个XML配置文件:web ...
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文件并没有进行过多的说明,很多人知其然不知其所以然,经过几天的搜索和整理,今天总算对其中的XML配置文件有了一定的了解,所以拿 ...
- Spring+SpringMVC整合----配置文件
1.在 web.xml 中加载 spring 的配置文件 bean.xml 底层是 Listener <!-- Spring --> <context-param> &l ...
- Eclipse Meaven Spring SpringMVC Mybaits整合
本示例是在:Ubuntu15上实现的:Windows上安装Maven将不太相同. Maven Install Run command sudo apt-get install maven, to in ...
随机推荐
- c#遍历一个对象中所有的属性和值
SpDictItem sp = GetCFHObject.GetSpItem("); PropertyInfo[] propertys = sp.GetType().GetPropertie ...
- PHP的ob_flush()与flush()区别
PHP的ob_flush()与flush()区别 标签: php ob-flush flush buffer 2017年03月24日 17:50:393248人阅读 评论(0) 收藏 举报 分类: ...
- Cocos2dx开发之运行与渲染流程分析
学习Cocos2dx,我们都知道程序是由 AppDelegate 的方法 applicationDidFinishLaunching 开始,在其中做些必要的初始化,并创建运行第一个 CCScene 即 ...
- 2019-04(1)(Python学习)
9.1 迭代器 创建迭代器的3种方法: 方法一: 容器对象添加 __iter__() 和 __next__() 方法(Python 2.7 中是 next()):__iter__() 返回迭代器对象本 ...
- oracle 按表数据新增一行
在功能实现时,能尽量用一个sql语句直接实现业务逻辑的话,就不要去写C#代码,便于维护. 以下sql的逻辑是:给明细表新增一条数据,前提是传入的债券代码存在与债券表,否则不新增.此sql返回受影响行数 ...
- ios 根据 schemes 打开 app
公司出需求,要让 h5链接直接打开用户的 app,如果没有安装 app 直接跳转到 appStore 这就需要给 app 配置 schemes 即可 1.在Info.plist中 LSApplicat ...
- IDEA cannot resolve symbol “xxxx”
有缓存 多试两次就可以了. 技术交流群:816227112
- rest_framework的视图组件继承过哪些类?
- Problem Description——用c语言实现素数的判定
Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数. Inp ...
- Json格式获取接口返回的值
关键字:Set Variable Get Json Value to json Get From Dictionary 具体关键字用法不再说明,可百度一下 ...