Mybatis框架,spring boot組件_Spring Boot Framework的關鍵組件和內部

 2023-11-19 阅读 31 评论 0

摘要: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

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

    彈簧啟動執行器

Mybatis框架?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等。我們將在以后的文章中討論這兩個組件。

springboot的優點、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)

Spring boot、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組件。

springboot中文手冊,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簡化了項目構建的依賴關系。

Spring Framework、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組件將負責提供這些信息。

springboot常用注解,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中。

bootstrap組件、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示例討論更多細節。

springboot核心、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應用程序。

springboot的核心注解、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 jpa。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 /”端點訪問此應用程序。

springboot的核心組件,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是如何在后臺運行的。

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)

SpringBoot項目?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了解更多詳細信息。

j2ee框架,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組件

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/183263.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息