Spring 和 Spring Boot 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30080855/
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:33:27  来源:igfitidea点击:

Difference between Spring and Spring Boot

springapirestspring-boot

提问by Cheps

There are many people who advised me to use Spring Boot instead of Spring to develop REST web services. I want to know what exactly the difference between the two is?

有很多人建议我使用 Spring Boot 而不是 Spring 来开发 REST web 服务。我想知道这两者到底有什么区别?

采纳答案by medvedev1088

In short

简而言之

  1. Spring Boot reduces the need to write a lot of configuration and boilerplate code.
  2. It has an opinionated view on Spring Platform and third-party libraries so you can get started with minimum effort.
  3. Easy to create standalone applications with embedded Tomcat/Jetty/Undertow.
  4. Provides metrics, health checks, and externalized configuration.
  1. Spring Boot 减少了编写大量配置和样板代码的需要。
  2. 它对 Spring Platform 和第三方库有一个固执的观点,因此您可以以最少的努力开始。
  3. 使用嵌入式 Tomcat/Jetty/Undertow 轻松创建独立应用程序。
  4. 提供指标、运行状况检查和外部化配置。

You can read more here http://projects.spring.io/spring-boot/

你可以在这里阅读更多http://projects.spring.io/spring-boot/

回答by digitaljoel

Basically, Spring Boot is an opinionated instance of a Spring application.

基本上,Spring Boot 是 Spring 应用程序的一个自以为是的实例。

Spring Boot is a rapid application development platform. It uses various components of Spring, but has additional niceties like the ability to package your application as a runnable jar, which includes an embedded tomcat (or jetty) server. Additionally, Spring Boot contains a LOT of auto-configuration for you (the opinionated part), where it will pick and choose what to create based on what classes/beans are available or missing.

Spring Boot 是一个快速的应用程序开发平台。它使用 Spring 的各种组件,但具有额外的优点,例如能够将您的应用程序打包为一个可运行的 jar,其中包括一个嵌入式 tomcat(或 jetty)服务器。此外,Spring Boot 为您提供了大量自动配置(自以为是的部分),它会根据可用或缺少的类/bean 来选择要创建的内容。

I would echo their sentiment that if you are going to use Spring I can't think of any reasons to do it without Spring Boot.

我会赞同他们的观点,如果你打算使用 Spring,我想不出没有 Spring Boot 的任何理由。

回答by Beezer

Unfortunately and I mean this out of personal frustration with Spring boot, I have yet to see any real quantified list, where the differences are explicitly outlined. There is only qualifications such as the rubbish sentence "...opinionated view..." which are bandied about.

不幸的是,我的意思是出于个人对 Spring boot 的不满,我还没有看到任何真正的量化列表,其中明确概述了差异。只有诸如废话“...固执的观点...”之类的资格。

What isclear, is that SpringBoot has wrapped up groups of Spring annotations into its own set of annotations, implicitly. Further obfuscating, and making the need for anyone starting out in SpringBoot to have to commit to memory what a particular SpringBoot annotation represents.

什么明确的,就是SpringBoot已经结束了春天的注释组到自己的注释集,含蓄。进一步混淆,并使任何开始使用 SpringBoot 的人都必须记住特定 SpringBoot 注释所代表的内容。

My reply therefore is of no quantifiable benefit to the original question, which is analogous to that of the SpringBoot authors. Those behind Spring IMO deliberately set-out to obfuscate, which reflects the obtuseness of their JavaDoc and API's (see SpringBatch API's as an example, if you think I am flaming) that makes one wonder the value of their open-source ethos.

因此,我的回答对原始问题没有任何可量化的好处,这类似于 SpringBoot 作者的回答。Spring IMO 背后的那些人故意开始混淆,这反映了他们的 JavaDoc 和 API 的迟钝(如果您认为我在发火,请参阅 SpringBatch API 的示例),这让人们怀疑他们的开源精神的价值。

My quest for figuring out SpringBoot continues.

我对 SpringBoot 的探索仍在继续。

回答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 bpjoshi

Spring Boot is opinionated view of Spring Framework projects.Let's analyse it through one program taken from Spring Boot Documentation.

Spring Boot 是 Spring Framework 项目的自以为是的观点。我们通过 Spring Boot 文档中的一个程序来分析它。

@RestController
@EnableAutoConfiguration
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Example.class, args);
    }
  }

It's a very basic REST API and you need to add Spring-boot-starter-webin your POM.xmlfor the same. Since you have added starter-web dependency, the annotation @EnableAutoConfigurationguesses that you want to develop a web application and sets up Spring accordingly.

这是一个非常基本的REST API,你需要添加Spring-boot-starter-web在你POM.xml的一样。由于您添加了 starter-web 依赖项,因此注解 @EnableAutoConfiguration猜测您要开发 Web 应用程序并相应地设置 Spring。

Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDBis on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.

Spring Boot 自动配置尝试根据您添加的 jar 依赖项自动配置您的 Spring 应用程序。例如,如果HSQLDB在您的 上classpath,并且您没有手动配置任何数据库连接 bean,那么 Spring Boot 会自动配置一个内存数据库。

It's opinionated like maven. Maven creates a project structure for you which it thinks is the general pattern of projects like it adds src/main/javafolder or resource folder for you.

它像 maven 一样自以为是。Maven 为您创建一个项目结构,它认为这是项目的一般模式,例如src/main/java为您添加文件夹或资源文件夹。

Spring boot helps in faster development. It has many starter projects that helps you get going quite faster. It also includes many non functional features like: embedded servers, security, metrics, health checks etc. In short, it makes, spring based application development easier with minimally invading code(Less configuration files, less no of annotations).

Spring Boot 有助于加快开发速度。它有许多入门项目,可以帮助您更快地进行。它还包括许多非功能特性,例如:嵌入式服务器、安全性、指标、健康检查等。简而言之,它使基于 spring 的应用程序开发更容易,侵入代码最少(更少的配置文件,更少的注释)。

Reference: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation-about

参考:https: //docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation-about

回答by Anil Jagtap

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

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

Spring Bootis 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被认为是固执己见的,即它大力提倡某种快速开发风格,但它的设计足够好,可以容纳规则的例外,如果你愿意的话。简而言之,它是一种约定俗成的配置方法论,愿意理解您在必要时打破约定的需要