Spring MVC 和 Spring Boot 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32922914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:48:33  来源:igfitidea点击:

Difference between Spring MVC and Spring Boot

springspring-mvcspring-boot

提问by Gero

I have just started learning Spring. In my next step, I would like to develop bigger web applications.

我刚刚开始学习Spring。在我的下一步中,我想开发更大的 Web 应用程序。

Now I am wondering if I should start with Spring Boot or Spring MVC. I have already read some stuff, but it is confusing because both look similar.

现在我想知道我应该从 Spring Boot 还是 Spring MVC 开始。我已经阅读了一些东西,但它令人困惑,因为两者看起来相似。

So what are the differences between the two?

那么两者有什么区别呢?

回答by Xtreme Biker

  • Spring MVCis a complete HTTP oriented MVC framework managed by the Spring Framework and based in Servlets. It would be equivalent to JSF in the JavaEE stack. The most popular elements in it are classes annotated with @Controller, where you implement methods you can access using different HTTP requests. It has an equivalent @RestControllerto implement REST-based APIs.
  • Spring bootis a utility for setting up applications quickly, offering an out of the box configuration in order to build Spring-powered applications. As you may know, Spring integrates a wide range of different modules under its umbrella, as spring-core, spring-data, spring-web(which includes Spring MVC, by the way) and so on. With this tool you can tell Spring how many of them to use and you'll get a fast setup for them (you are allowed to change it by yourself later on).
  • Spring MVC是一个完整的面向 HTTP 的 MVC 框架,由 Spring Framework 管理,基于 Servlets。它相当于 JavaEE 堆栈中的 JSF。其中最流行的元素是用 注释的类@Controller,您可以在其中实现可以使用不同 HTTP 请求访问的方法。它具有@RestController实现基于 REST 的 API的等效项。
  • Spring boot是一个用于快速设置应用程序的实用程序,提供开箱即用的配置以构建 Spring 驱动的应用程序。您可能知道,Spring 在其保护伞下集成了多种不同的模块,如spring-corespring-dataspring-web(顺便说一下,其中包括 Spring MVC)等。使用此工具,您可以告诉 Spring 使用多少个,并且您可以快速设置它们(您可以稍后自行更改)。

So, Spring MVC is a framework to be used in web applications and Spring Boot is a Spring based production-readyproject initializer. You might find useful visiting the Spring MVC tag wikias well as the Spring Boot tag wikiin SO.

因此,Spring MVC 是一个用于 Web 应用程序的框架,而 Spring Boot 是一个基于 Spring 的生产就绪项目初始值设定项。您可能会发现访问SO 中的Spring MVC 标记 wiki以及Spring Boot 标记 wiki很有用。

回答by Sanjay

Spring MVCand Spring Bootare well described in other answers, and so without repeating that, let me jump straight to the specifics. Spring Bootand Spring MVCare not comparable or mutually exclusive. If you want to do web application development using Spring, you would use Spring MVCanyway. Your question then becomes whether to use Spring Bootor not.

Spring MVCSpring Boot在其他答案中有很好的描述,所以不再重复,让我直接跳到具体细节。Spring BootSpring MVC没有可比性或相互排斥。如果您想使用 Spring 进行 Web 应用程序开发,无论如何您都会使用Spring MVC。那么您的问题就变成是否使用Spring Boot

For developing common Spring applications or starting to learn Spring, I think using Spring Bootwould be recommended. It considerably eases the job, is production ready and is rapidly being widely adopted.

对于开发常见的 Spring 应用程序或开始学习 Spring,我认为建议使用Spring Boot。它大大简化了工作,可用于生产并迅速被广泛采用。

I have seen sometimes beginners asking this question because in STS (Spring Tool Suite) there are two wizards: one for creating a Spring Boot project, and another for creating a Spring MVC project. So, my recommendation would be to create a Spring Boot project and choose Webas a module in that.

我有时看到初学者问这个问题,因为在 STS(Spring Tool Suite)中有两个向导:一个用于创建 Spring Boot 项目,另一个用于创建 Spring MVC 项目。因此,我的建议是创建一个 Spring Boot 项目并选择Web作为其中的模块。

回答by Bishal Jaiswal

In simple term it can be stated as:

简单来说可以表述为:

Spring boot = Spring MVC + Auto Configuration(Don't need to write spring.xml file for configurations) + Server(You can have embedded Tomcat, Netty, Jetty server).

Spring boot = Spring MVC + Auto Configuration(Don't need to write spring.xml file for configurations) + Server(You can have embedded Tomcat, Netty, Jetty server).

And Spring Boot is an Opinionated framework, so its build taking in consideration for fast development, less time need for configuration and have a very good community support.

而 Spring Boot 是一个 Opinionated 框架,所以它的构建考虑到了快速开发、更少的配置时间以及有很好的社区支持。

回答by Akash Singh Sengar

This is a pictorial representation of showing Difference.
Please refer to this linkfor more Info: enter image description here

这是显示差异的图示。
请参阅此链接了解更多信息: 在此处输入图片说明

Src of this Image

此图片的来源

回答by Web User

Spring MVCis a sub-project of the Spring Framework, targeting design and development of applications that use the MVC (Model-View-Controller) pattern. Spring MVC is designed to integrate fully and completely with the Spring Framework and transitively, most other sub-projects.

Spring MVC是 Spring Framework 的一个子项目,针对使用 MVC(模型-视图-控制器)模式的应用程序的设计和开发。Spring MVC 旨在与 Spring 框架和大多数其他子项目完全集成。

Spring Bootcan be understood quite well from this articleby the Spring Engineering team. It is supposedly opinionated, i.e. it heavily advocates a certain style of rapid development, but it is designed well enough to accommodate exceptions to the rule, if you will. In short, it is a convention over configuration methodology that is willing to understand your need to break convention when warranted.

Spring Boot从Spring Engineering 团队的这篇文章中可以很好地理解。它被认为是固执己见的,即它大力提倡某种快速开发风格,但它的设计足够好,可以容纳规则的例外,如果你愿意的话。简而言之,它是一种约定优于配置方法的约定,它愿意理解您在必要时打破约定的需要。

回答by Dhwanil Patel

Here is some main point which differentiate Spring, Spring MVC and Spring Boot :

以下是区分 Spring、Spring MVC 和 Spring Boot 的一些要点:

Spring :

春天 :

  1. Main Difference is "Test-ability".
  2. Spring come with the DI and IOC. Through which all hard-work done by system we don't need to do any kind of work(like, normally we define object of class manually but through Di we just annotate with @Service or @Component - matching class manage those).
  3. Through @Autowired annotation we easily mock() it at unit testing time.
  4. Duplication and Plumbing code. In JDBC we writing same code multiple time to perform any kind of database operation Spring solve that issue through Hibernate and ORM.
  5. Good Integration with other frameworks. Like Hibernate, ORM, Junit & Mockito.
  1. 主要区别在于“测试能力”。
  2. Spring 与 DI 和 IOC 一起出现。通过系统完成的所有艰苦工作,我们不需要做任何类型的工作(例如,通常我们手动定义类的对象,但通过 Di 我们只需使用 @Service 或 @Component 进行注释 - 匹配的类管理这些)。
  3. 通过@Autowired 注释,我们可以在单元测试时轻松地模拟()它。
  4. 复制和管道代码。在 JDBC 中,我们多次编写相同的代码来执行任何类型的数据库操作 Spring 通过 Hibernate 和 ORM 解决该问题。
  5. 与其他框架的良好集成。像 Hibernate、ORM、Junit 和 Mockito。

Spring MVC

春季MVC

  1. Spring MVC framework is module of spring which provide facility HTTP oriented web application development.
  2. Spring MVC have clear code separation on input logic(controller), business logic(model), and UI logic(view).
  3. Spring MVC pattern help to develop flexible and loosely coupled web applications.
  4. Provide various hard coded way to customise your application based on your need.
  1. Spring MVC 框架是 spring 的模块,提供面向 HTTP 的 Web 应用程序开发。
  2. Spring MVC 在输入逻辑(控制器)、业务逻辑(模型)和 UI 逻辑(视图)上有明确的代码分离。
  3. Spring MVC 模式有助于开发灵活且松散耦合的 Web 应用程序。
  4. 提供各种硬编码方式来根据您的需要自定义您的应用程序。

Spring Boot :

弹簧靴:

  1. Create of Quick Application so that, instead of manage single big web application we divide them individually into different Microservices which have their own scope & capability.
  2. Auto Configuration using Web Jar : In normal Spring there is lot of configuration like DispatcherServlet, Component Scan, View Resolver, Web Jar, XMLs. (For example if I would like to configure datasource, Entity Manager Transaction Manager Factory). Configure automatically when it's not available using class-path.
  3. Comes with Default Spring Starters, which come with some default Spring configuration dependency (like Spring Core, Web-MVC, Hymanson, Tomcat, Validation, Data Binding, Logging). Don't worry about versioning issue as well.
  1. 创建快速应用程序,以便我们将它们单独划分为不同的微服务,而不是管理单个大型 Web 应用程序,这些微服务具有自己的范围和功能。
  2. 使用 Web Jar 的自动配置:在普通 Spring 中有很多配置,如 DispatcherServlet、组件扫描、视图解析器、Web Jar、XML。(例如,如果我想配置数据源,实体管理器事务管理器工厂)。使用类路径不可用时自动配置。
  3. 带有默认的 Spring Starters,它带有一些默认的 Spring 配置依赖项(如 Spring Core、Web-MVC、Hymanson、Tomcat、Validation、Data Binding、Logging)。也不要担心版本问题。

(Evolution like : Spring -> Spring MVC -> Spring Boot, So newer version have the compatibility of old version features.) Note : It doesn't contain all point.

(演变如:Spring -> Spring MVC -> Spring Boot,因此新版本具有旧版本特性的兼容性。) 注意:它不包含所有要点。

回答by Yasir Shabbir Choudhary

SpringBoot is actually pre configured that reduced boiler configuration and providing easiest or quick way to start your application.

SpringBoot 实际上是预先配置的,它减少了锅炉配置,并提供了启动应用程序的最简单或快速的方法。

SpringBoot take the headache of configuration from developer to it's own self rather than Spring.

SpringBoot 将开发人员的配置问题转移到了它自己而不是 Spring 上。

Implicitly SpringBoot is based on Spring framework concept like bean, controller , services, jpa etc.

隐式 SpringBoot 基于 Spring 框架概念,如 bean、控制器、服务、jpa 等。

You can say that SpringBoot is a wrapper of Spring.

可以说 SpringBoot 是 Spring 的封装。

In SpringBoot by default port of Server is 8080 but if you want to change then go to your application.properties and write

在 SpringBoot 中,Server 的默认端口是 8080 但如果你想改变然后去你的 application.properties 并写

server.port = 8084

服务器端口 = 8084

回答by Leanghak

  • Using spring boot you will no need to build configuration. This will have done automatically when you create project.

  • If you use spring MVC you need to build configuration yourself. It is more complicated, but it is crucial.

  • 使用 spring boot 你不需要构建配置。这将在您创建项目时自动完成。

  • 如果您使用 spring MVC,则需要自己构建配置。它更复杂,但很关键。

回答by Indrajith Ekanayake

Without repeating the same thing in previous answers,
I'm writing this answer for the people who are looking to starting a new project and don't know which is the best framework to startup your project. If you are a beginner to this framework the best thing I prefer is Use spring boot(with STS /Spring Tool Suite). Because it helps a lot. Its do all configurations on its own. Additionally, use Hibernatewith spring-boot as a database framework. With this combination, your application will be the best. I can guarantee that with my experiences.

在不重复以前的答案中的相同内容的情况下,
我正在为那些希望开始一个新项目但不知道哪个是启动项目的最佳框架的人写这个答案。如果你是这个框架的初学者,我更喜欢使用spring boot(with STS / Spring Tool Suite)。因为它有很大帮助。它自己完成所有配置。此外,使用带有 spring-boot 的Hibernate作为数据库框架。通过这种组合,您的应用程序将是最好的。我可以保证,以我的经验。

Even this is one of the best frameworks for JEE(in present) this is gonna die in the near future. There are lightweight alternatives coming up. So keep updated with your experience don't stick to one particular framework. The best thing is being fluent in concepts, not in the frameworks.

即使这是 JEE 的最佳框架之一(目前),它也会在不久的将来消亡。有轻量级的替代品出现。因此,不断更新您的经验,不要拘泥于一个特定的框架。最好的事情是精通概念,而不是框架。

回答by Armando Microsse

Think this way:

这样想:

Spring MVCis a web based framework to implement the MVC architecture.

Spring MVC是一个基于 Web 的框架,用于实现 MVC 架构。

Spring Bootis a tool oriented to the programmer. Programmer must focus on programming and tool must focus on configurations. So we don't need to wast our time configuring a bunch of xml to make a simple 'Hello world'.

Spring Boot是一个面向程序员的工具。程序员必须专注于编程,工具必须专注于配置。所以我们不需要浪费时间配置一堆 xml 来制作一个简单的“Hello world”。