spring boot组件

In my previous post “Introduction to Spring Boot”, we have discussed about Spring Boot basics. Now we will discuss about “What are the main components of Spring Boot” and “How Spring Boot works under-the-hood”.

在我以前的文章“ Spring Boot简介”中 ,我们讨论了有关Spring Boot的基础知识。 现在,我们将讨论“ Spring Boot的主要组件是什么”和“ Spring Boot如何在后台运行”。

Spring Boot Framework的关键组件 (Key Components of Spring Boot Framework)

Spring Boot Framework has mainly four major Components.

Spring Boot Framework主要包含四个主要组件。

  • Spring Boot Starters
    Spring启动启动器
  • Spring Boot AutoConfigurator
    Spring Boot自动配置器
  • Spring Boot CLI
    Spring Boot CLI
  • Spring Boot Actuator
    弹簧启动执行器

NOTE:-
In addition to these four major components, there are two more Spring Boot components:

注意:-
除了这四个主要组件之外,还有另外两个Spring Boot组件:

  • Spring Initilizr
    Spring倡议
  • Spring Boot IDEs
    Spring Boot IDE

To quick start new Spring Boot projects, we can use “Spring Initializr” web interface. Spring Initializr URL: https://start.spring.io.

为了快速启动新的Spring Boot项目,我们可以使用“ Spring Initializr” Web界面。 Spring Initializr URL:https://start.spring.io。

We have many Spring Boot IDEs like Eclipse IDE, IntelliJ IDEA, Spring STS Suite etc. We will discuss these two components in coming posts.

我们有许多Spring Boot IDE,例如Eclipse IDE,IntelliJ IDEA,Spring STS Suite等。我们将在以后的文章中讨论这两个组件。

Now we will discuss these Spring Boot four components one by one in detail.

现在,我们将详细讨论这些Spring Boot的四个组件。

Spring Boot Starter (Spring Boot Starter)

Spring Boot Starters is one of the major key features or components of Spring Boot Framework. The main responsibility of Spring Boot Starter is to combine a group of common or related dependencies into single dependencies. We will explore this statement in detail with one example.

Spring Boot Starters是Spring Boot Framework的主要关键功能或组件之一。 Spring Boot Starter的主要职责是将一组常见或相关的依赖项组合为单个依赖项。 我们将通过一个示例详细探讨该声明。

For instance, we would like to develop a Spring WebApplication with Tomcat WebServer. Then we need to add the following minimal jar dependencies in your Maven’s pom.xml file or Gradle’s build.gradle file

例如,我们想用Tomcat WebServer开发一个Spring WebApplication。 然后,我们需要在Maven的pom.xml文件或Gradle的build.gradle文件中添加以下最小jar依赖项

  • Spring core Jar file(spring-core-xx.jar)
    Spring核心Jar文件(spring-core-xx.jar)
  • Spring Web Jar file(spring-web-xx.jar)
    Spring Web Jar文件(spring-web-xx.jar)
  • Spring Web MVC Jar file(spring-webmvc-xx.jar)
    Spring Web MVC Jar文件(spring-webmvc-xx.jar)
  • Servlet Jar file(servlet-xx.jar)
    Servlet Jar文件(servlet-xx.jar)

If we want to add some database stuff, then we need to add database related jars like Spring JDBC jar file, Spring ORM jar files,Spring Transaction Jar file etc.

如果我们要添加一些数据库内容,那么我们需要添加与数据库相关的jar,例如Spring JDBC jar文件,Spring ORM jar文件,Spring Transaction Jar文件等。

  • Spring JDBC Jar file(spring-jdbc-xx.jar)
    Spring JDBC Jar文件(spring-jdbc-xx.jar)
  • Spring ORM Jar file(spring-orm-xx.jar)
    Spring ORM Jar文件(spring-orm-xx.jar)
  • Spring Transaction Jar file(spring-transaction-xx.jar)
    Spring Transaction Jar文件(spring-transaction-xx.jar)

We need to define lot of dependencies in our build files. It is very tedious and cumbersome tasks for a Developer. And also it increases our build file size.

我们需要在构建文件中定义很多依赖项。 对于开发人员而言,这是非常繁琐且繁琐的任务。 而且它还会增加我们的构建文件大小。

What is the solution to avoid this much dependencies definitions in our build files? The solution is Spring Boot Starter component.

有什么解决方案可以避免在构建文件中出现如此多的依赖项定义? 解决方案是Spring Boot Starter组件。

Spring Boot Starter component combines all related jars into single jar file so that we can add only jar file dependency to our build files. Instead of adding above 4 jars files to our build file, we need to add one and only one jar file: “spring-boot-starter-web” jar file.

Spring Boot Starter组件将所有相关的jar组合到单个jar文件中,因此我们只能将jar文件依赖项添加到我们的构建文件中。 无需将上述4个jar文件添加到我们的构建文件中,我们需要添加一个并且仅添加一个jar文件:“ spring-boot-starter-web” jar文件。

When we add “spring-boot-starter-web” jar file dependency to our build file, then Spring Boot Framework will automatically download all required jars and add to our project classpath.

当我们在构建文件中添加“ spring-boot-starter-web” jar文件依赖项时,Spring Boot Framework将自动下载所有必需的jar并添加到我们的项目类路径中。

In the same way, “spring-boot-starter-logging” jar file loads all it’s dependency jars like “jcl-over-slf4j, jul-to-slf4j,log4j-over-slf4j, logback-classic” to our project classpath.

以同样的方式,“ spring-boot-starter-logging” jar文件将其所有依赖项jar诸如“ jcl-over-slf4j,jul-to-slf4j,log4j-over-slf4j,logback-classic”加载到我们的项目类路径中。

Spring Boot Starter的主要优点 (Major Advantages of Spring Boot Starter)

  • Spring Boot Starter reduces defining many dependencies simplify project build dependencies.
    Spring Boot Starter减少了许多依赖的定义,简化了项目构建的依赖。
  • Spring Boot Starter simplifies project build dependencies.
    Spring Boot Starter简化了项目构建的依赖关系。

That’s it about Spring Boot Starter component. We will discuss some more details with some Spring Boot examples in coming posts.

就是关于Spring Boot Starter组件。 我们将在以后的文章中通过一些Spring Boot示例讨论更多细节。

Spring Boot自动配置器 (Spring Boot AutoConfigurator)

Another important key component of Spring Boot Framework is Spring Boot AutoConfigurator. Most of the Spring IO Platform (Spring Framework) Critics opinion is that “To develop a Spring-based application requires lot of configuration (Either XML Configuration of Annotation Configuration). Then how to solve this problem.

Spring Boot Framework的另一个重要关键组件是Spring Boot AutoConfigurator。 大部分Spring IO平台(Spring框架)的批评者认为,“开发基于Spring的应用程序需要大量配置(Annotation Configuration的XML Configuration)。 那么如何解决这个问题。

The solution to this problem is Spring Boot AutoConfigurator. The main responsibility of Spring Boot AutoConfigurator is to reduce the Spring Configuration. If we develop Spring applications in Spring Boot,then We dont need to define single XML configuration and almost no or minimal Annotation configuration. Spring Boot AutoConfigurator component will take care of providing those information.

这个问题的解决方案是Spring Boot AutoConfigurator。 Spring Boot AutoConfigurator的主要职责是减少Spring配置。 如果我们在Spring Boot中开发Spring应用程序,那么我们就不需要定义单个XML配置,而几乎不需要或只需很少的Annotation配置。 Spring Boot AutoConfigurator组件将负责提供这些信息。

For instance, if we want to declare a Spring MVC application using Spring IO Platform, then we need to define lot of XML Configuration like views, view resolvers etc. But if we use Spring Boot Framework, then we dont need to define those XML Configuration. Spring Boot AutoConfigurator will take of this.

例如,如果我们想使用Spring IO Platform声明一个Spring MVC应用程序,那么我们需要定义很多XML配置,例如视图,视图解析器等。但是,如果我们使用Spring Boot Framework,那么我们就不需要定义那些XML配置。 。 Spring Boot AutoConfigurator将采用此功能。

If we use “spring-boot-starter-web” jar file in our project build file, then Spring Boot AutoConfigurator will resolve views, view resolvers etc. automatically.

如果我们在项目构建文件中使用“ spring-boot-starter-web” jar文件,则Spring Boot AutoConfigurator将自动解析视图,视图解析器等。

And also Spring Boot reduces defining of Annotation configuration. If we use @SpringBootApplication annotation at class level, then Spring Boot AutoConfigurator will automatically add all required annotations to Java Class ByteCode.

而且,Spring Boot减少了注释配置的定义。 如果我们在类级别使用@SpringBootApplication注释,那么Spring Boot AutoConfigurator将自动将所有必需的注释添加到Java类ByteCode中。

If we go through Spring Boot Documentation, we can find the following definition for @SpringBootApplication.

如果我们阅读Spring Boot Documentation,我们可以为@SpringBootApplication找到以下定义。

@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Inherited
@Configuration
@EnableAutoConfiguration
@ComponentScan
public @interface SpringBootApplication

That is, @SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiration.

也就是说,@SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiration。

That’s it about Spring Boot AutoConfigurate component. We will discuss some more details with some Spring Boot examples in coming posts.

就是关于Spring Boot AutoConfigurate组件。 我们将在以后的文章中通过一些Spring Boot示例讨论更多细节。

NOTE:-

注意:-

  • In simple words, Spring Boot Starter reduces build’s dependencies and Spring Boot AutoConfigurator reduces the Spring Configuration.
    简而言之,Spring Boot Starter减少了构建的依赖关系,而Spring Boot AutoConfigurator减少了Spring配置。
  • As we discussed that Spring Boot Starter has a dependency on Spring Boot AutoConfigurator, Spring Boot Starter triggers Spring Boot AutoConfigurator automatically.
    正如我们所讨论的,Spring Boot Starter依赖于Spring Boot AutoConfigurator,Spring Boot Starter自动触发Spring Boot AutoConfigurator。

Spring Boot CLI (Spring Boot CLI)

Spring Boot CLI(Command Line Interface) is a Spring Boot software to run and test Spring Boot applications from command prompt. When we run Spring Boot applications using CLI, then it internally uses Spring Boot Starter and Spring Boot AutoConfigurate components to resolve all dependencies and execute the application.

Spring Boot CLI(命令行界面)是一种Spring Boot软件,用于从命令提示符下运行和测试Spring Boot应用程序。 当我们使用CLI运行Spring Boot应用程序时,它会在内部使用Spring Boot Starter和Spring Boot AutoConfigurate组件来解析所有依赖关系并执行该应用程序。

We can run even Spring Web Applications with simple Spring Boot CLI Commands.

我们甚至可以使用简单的Spring Boot CLI命令运行Spring Web应用程序。

Spring Boot CLI has introduced a new “spring” command to execute Groovy Scripts from command prompt.

Spring Boot CLI引入了一个新的“ spring”命令来从命令提示符处执行Groovy脚本。

spring command example:

弹簧命令示例:

spring run HelloWorld.groovy

Here HelloWorld.groovy is a Groovy script FileName. Like Java source file names have *.java extension, Groovy script files have *.groovy extension. “spring” command executes HelloWorld.groovy and produces output.

这里的HelloWorld.groovy是一个Groovy脚本FileName。 就像Java源文件的名称具有* .java扩展名一样,Groovy脚本文件的名称也具有* .groovy扩展名。 “ spring”命令执行HelloWorld.groovy并产生输出。

Spring Boot CLI component requires many steps like CLI Installation, CLI Setup, Develop simple Spring Boot application and test it. So we are going to dedicate another post to discuss it in details with some Spring Boot Examples. Please refer my next post on Spring Boot CLI.

Spring Boot CLI组件需要许多步骤,例如CLI安装,CLI设置,开发简单的Spring Boot应用程序并进行测试。 因此,我们将专门讨论另一篇文章,并提供一些Spring Boot实例进行详细讨论。 请参考我在Spring Boot CLI上的下一篇文章。

弹簧启动执行器 (Spring Boot Actuator)

Spring Boot Actuator components gives many features, but two major features are

Spring Boot Actuator组件具有许多功能,但其中两个主要功能是

  • Providing Management EndPoints to Spring Boot Applications.
    为Spring Boot应用程序提供管理端点。
  • Spring Boot Applications Metrics.
    Spring Boot应用程序度量标准。

When we run our Spring Boot Web Application using CLI, Spring Boot Actuator automatically provides hostname as “localhost” and default port number as “8080”. We can access this application using “https://localhost:8080/” end point.

当我们使用CLI运行Spring Boot Web应用程序时,Spring Boot Actuator会自动提供主机名“ localhost”和默认端口号“ 8080”。 我们可以使用“ https:// localhost:8080 /”端点访问此应用程序。

We actually use HTTP Request methods like GET and POST to represent Management EndPoints using Spring Boot Actuator.

实际上,我们使用诸如GET和POST之类的HTTP请求方法来使用Spring Boot Actuator表示管理端点。

We will discuss some more details about Spring Boot Actuator in coming posts.

我们将在以后的文章中讨论有关Spring Boot Actuator的更多详细信息。

Spring Boot Framework的内部 (Internals of Spring Boot Framework)

It’s always recommended to understand how Spring Boot Framework reduces build’s dependencies,Spring Configuration, etc. How Spring Boot works under-the-hood.

始终建议您了解Spring Boot Framework如何减少构建的依赖关系,Spring Configuration等。SpringBoot是如何在后台运行的。

If you are familiar with Groovy Programming language, then you know most of the stuff. In Groovy, we don’t need to add some some imports and no need to add some dependencies to Groovy project. When we compile Groovy scripts using Groovy Compiler(groovyc), it will automatically adds all default import statements then compile it.

如果您熟悉Groovy编程语言,那么您将了解大多数内容。 在Groovy中,我们不需要添加一些导入,也不需要在Groovy项目中添加一些依赖项。 当我们使用Groovy Compiler(groovyc)编译Groovy脚本时,它将自动添加所有默认导入语句,然后对其进行编译。

In the same way, Groovy Programming language contains a JAR Dependency Resolver to resolve and add all required jar files to Groovy Project classpath.

同样,Groovy编程语言包含一个JAR依赖关系解析器,用于解析所有必需的jar文件并将其添加到Groovy Project类路径。

Spring Boot Framework internally uses Groovy to add some defaults like Default import statements, Application main() method etc. When we run Groovy Scripts from CLI Command prompt, it uses this main() method to run the Spring Boot Application.

Spring Boot Framework在内部使用Groovy添加一些默认值,例如Default import语句,Application main()方法等。当我们从CLI命令提示符运行Groovy脚本时,它使用此main()方法运行Spring Boot Application。

葡萄 (Grape)

Grape is an Embedded Dependency Resolution engine. Grape is a JAR Dependency Manager embedded into Groovy. Grape lets us quickly add maven repository dependencies to our project classpath to reduce build file definitions.

Grape是嵌入式依赖关系解决方案引擎。 Grape是嵌入Groovy的JAR依赖管理器。 Grape让我们快速将maven仓库依赖项添加到我们的项目类路径中,以减少构建文件的定义。

Spring Boot Framework programming model is mainly inspired by Groovy Programming model. Spring Boot Framework internally depends on these two major components: Groovy and Grape.

Spring Boot Framework编程模型主要是受Groovy编程模型启发的。 Spring Boot Framework在内部取决于这两个主要组件:Groovy和Grape。

You can refer Grape documentation https://docs.groovy-lang.org/latest/html/documentation/grape.html for more details.

您可以参考Grape文档https://docs.groovy-lang.org/latest/html/documentation/grape.html了解更多详细信息。

That’s it about Spring Components and Internals. We will discuss about these components in details with some Spring Boot examples in coming posts.

就是关于Spring Components和Internals。 我们将在后续文章中通过一些Spring Boot示例详细讨论这些组件。

If you have any queries, please drop me a comment.

如有任何疑问,请给我留言。

翻译自: https://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework

spring boot组件

spring boot组件_Spring Boot Framework的关键组件和内部相关推荐

  1. Spring Boot Framework的关键组件和内部构造(自动装配、起步依赖、CLI、Actuator)

    Spring Boot Framework的关键组件和内部组件 在我之前的文章"Spring Boot简介"中,我们讨论了Spring Boot基础知识.现在我们将讨论" ...

  2. spring boot面试_Spring Boot面试问题

    spring boot面试 Today we will look into some spring boot interview questions and answers. So far, we h ...

  3. spring cloud入门_Spring Boot 2.x基础教程:快速入门

    简介 在您第1次接触和学习Spring框架的时候,是否因为其繁杂的配置而退却了?在你第n次使用Spring框架的时候,是否觉得一堆反复黏贴的配置有一些厌烦?那么您就不妨来试试使用Spring Boot ...

  4. spring boot程序_Spring Boot –现代Java应用程序的基础

    spring boot程序 Spring Boot是Spring.io中一个相对较新的项目. 其目的是简化创建新的基于Spring Framework的项目,并通过应用一些约定来统一其配置. 这种关于 ...

  5. spring boot简介_Spring Boot简介

    spring boot简介 在本教程中,我们将看一下Spring Boot,看看它与Spring框架有何不同. 我们还将讨论Spring Boot提供的各种功能. 什么是Spring Boot? 在开 ...

  6. spring boot示例_Spring Boot完成示例

    spring boot示例 这篇文章提供了一个使用Spring Boot开发松耦合的REST服务的完整示例. 使用spring boot,我们可以开发可独立运行的生产就绪的Java应用程序,使其成为独 ...

  7. spring boot缓存_Spring Boot和缓存抽象

    spring boot缓存 缓存是大多数应用程序的主要组成部分,只要我们设法避免磁盘访问,缓存就会保持强劲. Spring对各种配置的缓存提供了强大的支持 . 您可以根据需要简单地开始,然后进行更多可 ...

  8. spring boot示例_Spring Boot REST示例

    spring boot示例 Spring Boot is an awesome module from Spring Framework. Once you are used to it, then ...

  9. spring boot 缓存_Spring Boot 集成 Redis 实现数据缓存

    Spring Boot 集成 Redis 实现数据缓存,只要添加一些注解方法,就可以动态的去操作缓存了,减少代码的操作. 在这个例子中我使用的是 Redis,其实缓存类型还有很多,例如 Ecache. ...

最新文章

  1. (五)磁盘存储空间的管理
  2. js 将时间戳转为日期格式
  3. 一个好用的开源在线时序图/波形图(Timing Diagram)绘制网站
  4. Python3.x 发送邮件
  5. C#LeetCode刷题之#344-反转字符串​​​​​​​(Reverse String)
  6. 列表推导(list comprehension)--Python
  7. 【华为云技术分享】Python 中的异常和错误
  8. 【数据结构】4.1图的创建及DFS深度遍历(不完善)
  9. .net环境下如何使用MySql数据库
  10. 停止预览时调用Camera.release(), 出现Method called after release()异常问题原因及解决办法...
  11. 黑客,计算机革命的英雄!
  12. Cocos2d-x下Lua调用自定义C++类和函数的最佳实践[转]
  13. 雷锋实验室:Evernote的中国门徒
  14. 计算机软件项目的效益预测,软件工程经济效益分析.doc
  15. 狂神说SpringMVC
  16. windows变量环境
  17. 如何把项目上传到Gitee(全网最细)
  18. init和destory方法
  19. 结对编程的合作情况,以及结对编程的优缺点
  20. Vue生命周期及store

热门文章

  1. Asp.net中Global.asax
  2. C:\WINDOWS\system32\drivers\etc\hosts
  3. [转载] 使用神经网络和ml模型预测客户流失
  4. WEB 端批量移动设备管理控制工具 STF 的环境搭建和运行
  5. 2018-2019-1 20189208《Linux内核原理与分析》第九周作业
  6. (转)Spring对注解(Annotation)处理源码分析1——扫描和读取Bean定义
  7. 【OpenCV新手教程之十三】OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放...
  8. ubuntu14.04 截图
  9. python---之阿partial
  10. PyTorch 入坑六 数据处理模块Dataloader、Dataset、Transforms