我刚刚开始学习春天。在我的下一步,我想开发更大的网络应用程序。

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

那么两者之间有什么不同呢?


当前回答

使用spring引导,您将不需要构建配置。这将在您创建项目时自动完成。 如果你使用spring MVC,你需要自己构建配置。它更复杂,但也至关重要。

其他回答

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 Hibernate with spring-boot as a database framework. With this combination, your application will be the best. I can guarantee that with my experiences.

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

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

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

Spring MVC is 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 @RestController to implement REST-based APIs. Spring boot is 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是一个用于web应用程序的框架,Spring Boot是一个基于Spring的生产就绪项目初始化器。您可能会发现访问Spring MVC标记wiki以及SO中的Spring Boot标记wiki很有用。

Spring MVC和Spring Boot在其他答案中有很好的描述,所以不再重复,让我直接跳到细节。Spring Boot和Spring MVC并不具有可比性或互斥性。如果你想使用Spring进行web应用程序开发,无论如何你都会使用Spring MVC。接下来的问题是是否使用Spring Boot。

对于开发普通Spring应用程序或开始学习Spring,我认为建议使用Spring Boot。它极大地减轻了工作,已投入生产,并迅速被广泛采用。

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

简单来说,它可以表述为:

Spring boot = Spring MVC +自动配置(不需要编写Spring .xml文件进行配置)+服务器(您可以有嵌入式Tomcat, Netty, Jetty服务器)。

Spring Boot是一个opiniated框架,因此它的构建考虑到了开发速度快,配置时间短,并且有很好的社区支持。