一、Spring版本

  Spring的最新版本是Spring 5.x,Spring 4.x的最后版本是Spring 4.3.x,会维护到2020年(Spring的GitHub主页对此有说明)。

  

  二、SpringMVC

  SpringMVC可以说是,应用了Spring的各种特性的一个MVC项目,它的核心Servlet是DispatcherServlet。

  三、配置

  各种Java框架一般都需要在web.xml中进行相关配置,一般都涉及到Listener、Filter、Servlet。

  3.1 web.xml中配置

  在Spring 3.1版本之前,在web.xml中配置DispatcherServlet是唯一的方式(同时声明映射):

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class> <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/dispatcher-config.xml</param-value>
</init-param> <load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

**注释:load-on-startup is an integer value that specifies the order for multiple servlets to be loaded. So if you need to declare more than one servlet you can define in which order they will be initialized. Servlets marked with lower integers are loaded before servlets marked with higher integers.

  3.2 web.xml和Java类中均可配置,即可混合配置

  接下来,随着Servlet API 3.0的应用,web.xml中的配置不是必须的了,我们可以在Java类中配置DispatcherServlet:

public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
XmlWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocation("/WEB-INF/spring/dispatcher-config.xml"); ServletRegistration.Dynamic dispatcher = container
.addServlet("dispatcher", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}

  这里的Java配置类取得的最终效果与3.1节中的相同。

  但是我们仍然使用了一个XML文件:dispatcher-config.xml

  3.3 100%的Java配置

  通过对3.2节中的Java配置类进行重构,我们无需再使用XML文件来配置Dispatcher:

public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext context
= new AnnotationConfigWebApplicationContext();      //context.register(AppConfig.class);
context.setConfigLocation("com.example.app.config"); container.addListener(new ContextLoaderListener(context)); ServletRegistration.Dynamic dispatcher = container
.addServlet("dispatcher", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}

**注释:

  The first thing we will need to do is create the application context for the servlet.

  This time we will use an annotation based context so that we can use Java and annotations for configuration and remove the need for XML files like dispatcher-config.xml.

  3.4 总结

  Spring 3.2及其以上的版本,均可以采用以上三种方式进行配置。

  官方推荐纯Java类来配置,更加简洁和灵活。但是有时候必须XML文件也是无法避免的

四、SpringBoot化繁为简

  这些配置很繁琐,SpringBoot就是达到一键生成的效果!

  

Spring、SpringMVC版本及配置的更多相关文章

  1. idea spring+springmvc+mybatis环境配置整合详解

    idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2. ...

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

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

  3. swagger-ui 系统配置过程(基于spring+springmvc+swagger+springfox配置 web-api 管理系统)

    web工程部分框架信息:spring springmvc swagger springfox maven 参考文档:https://www.cnblogs.com/exmyth/p/7183753.h ...

  4. Spring+SpringMVC+MyBatis整合配置

    前端控制器 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=& ...

  5. spring+springmvc+mybatis构建系统

    今天和大家分享的是spring+springmvc+mybatis搭建框架的例子,说到这里不得不说现在市面上一流大公司还有很多用这种架子,创业型公司大部分都用springboot集成的mvc+myba ...

  6. 【Spring】Spring+SpringMVC+MyBatis框架的搭建

    1,SSM的简介 SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架. 其中s ...

  7. SpringMVC入门二:SSM整合(spring+springmvc+mybatis)

    一.编程步骤 1.引入依赖 spring.springmvc.mybatis.mybatis-spring.mysql.druid.log4j.servlet-api.jstl.fastjson 2. ...

  8. 2.配置Spring+SpringMvc+Mybatis(分库or读写分离)--Intellij IDAE 2016.3.5

    建立好maven多模块项目后,开始使用ssm传统的框架: 1.打开总工程下的pom.xml文件:添加如下代码: <!--全局的所有版本号定义--> <properties> & ...

  9. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)

    用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 搭建目录环境和依赖) 四:在\resources\spring 下面 ...

随机推荐

  1. 发现一个好的手机抓包工具Http Traffic

    ---恢复内容开始--- 晚上加班闲着没事,喜欢抓包,逛破解论坛,看到他们在聊Http Traffic手机抓包工具, 就下载了打算玩玩 Http Traffic: 是 HTTP 抓包调试工具 HTTP ...

  2. Oracle JDBC 连接池

    1.简介 数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据 ...

  3. vue js select下拉框

    <template> <ul id="select"> <li> <div class="select-head"&g ...

  4. 【Python】对我自己的博客进行统计,看看哪年哪月发帖量最大

    代码很简单,主要利用了requests进行网络访问,beautifulSoup进行页面文本分析,re进行正则表达式抽取文字,前面两个需要pip install name去安装,后者是内部对象所以不用安 ...

  5. 在调试linux的休眠功能时如何打开调试信息开关?

    答:在bootargs中添加参数no_console_suspend即可进行调试

  6. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_24-页面预览-页面预览测试

    通过nginx转发到预览的地址 重启nginx 添加页面预览按钮 调整下列表的列的宽度

  7. 阶段5 3.微服务项目【学成在线】_day03 CMS页面管理开发_13-删除页面-前端-Api调用

    增加删除链接 <el-button size="small" type="text" @click="del(page.row.pageId)& ...

  8. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_05-vuejs研究-vuejs基础-v-text指令

    把js移到body 的下面 网速改慢一点 通过模拟网速慢的情况.刷新页面的时候会有闪烁的效果 速度快的情况下也会闪烁 ,只不过是不明显. 2.解决插值表达式闪烁问题,使用v-text v-text可以 ...

  9. [dart学习]第五篇:操作符

    前言:本系列内容假设读者有一定的编程基础,如了解C语言.python等. 本节一起来学习dart的操作符,直接拷贝官网的操作符描述表如下: Description Operator unary pos ...

  10. iOS tableview的常用delegate和dataSource执行顺序

    在这次项目中遇到了一个特别奇葩的问题:表视图创建的cell在7以上的系统能正常运行显示,在模拟器上就不能正常实现......为解决这个问题,纠结了好久...... 对在7系统上不显示的猜测: 用mas ...