原文地址:http://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework

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”.

Key Components of Spring Boot Framework

Spring Boot Framework has mainly four major Components.

  • Spring Boot Starters
  • Spring Boot AutoConfigurator
  • Spring Boot CLI
  • Spring Boot Actuator

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

  • Spring Initilizr
  • Spring Boot IDEs

To quick start new Spring Boot projects, we can use “Spring Initializr” web interface. Spring Initializr URL: http://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.

SpringBootComponents

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

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.

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

  • Spring core Jar file(spring-core-xx.jar)
  • Spring Web Jar file(spring-web-xx.jar)
  • Spring Web MVC Jar file(spring-webmvc-xx.jar)
  • Servlet Jar file(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.

  • Spring JDBC Jar file(spring-jdbc-xx.jar)
  • Spring ORM Jar file(spring-orm-xx.jar)
  • Spring Transaction Jar file(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 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.

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-dependencies

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.

Major Advantages of Spring Boot Starter

  • Spring Boot Starter reduces defining many dependencies simplify project build dependencies.
  • Spring Boot Starter simplifies project build dependencies.

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

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.

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.

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.

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.

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.

SpringBootApplicationAnnotation

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

1
2
3
4
5
6
7
8
@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Inherited
@Configuration
@EnableAutoConfiguration
@ComponentScan
public @interface SpringBootApplication

That is, @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.

NOTE:-

  • In simple words, Spring Boot Starter reduces build’s dependencies and Spring Boot AutoConfigurator reduces the Spring Configuration.
  • As we discussed that Spring Boot Starter has a dependency on Spring Boot AutoConfigurator, Spring Boot Starter triggers Spring Boot AutoConfigurator automatically.

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.

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

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

spring command example:

1
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.

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 Actuator

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

  • Providing Management EndPoints to Spring Boot Applications.
  • Spring Boot Applications Metrics.

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 “http://localhost:8080/” end point.

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

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

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.

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.

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

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.

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.

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.

springboot-internals

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

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

转载于:https://www.cnblogs.com/davidwang456/p/5569082.html

Key Components and Internals of Spring Boot Framework--转相关推荐

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

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

  2. spring boot组件_Spring Boot Framework的关键组件和内部

    spring boot组件 In my previous post "Introduction to Spring Boot", we have discussed about S ...

  3. (附源码)spring boot校园购物网站 毕业设计041037

    springboot校园购物网站APP 摘要 21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所 ...

  4. APP+spring boot校园购物网站 毕业设计-附源码041037

    springboot校园购物网站APP 摘 要 21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们 ...

  5. (附源码)APP+spring boot校园购物网站 毕业设计 041037

    springboot校园购物网站APP 摘 要 21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们 ...

  6. (附源码)spring boot社区居民健康档案管理系统 毕业设计 220940

    springboot 社区居民健康档案管理系统 摘 要 目前随着人们对健康认识的不断深入,健康观念也正在由有病治病向无病预防的方向改变,人们开始更加注重生活的质量,追求更健康,更长寿.因此,开发一个面 ...

  7. spring boot社区居民健康档案管理系统毕业设计源码220940

    springboot 社区居民健康档案管理系统 摘 要 目前随着人们对健康认识的不断深入,健康观念也正在由有病治病向无病预防的方向改变,人们开始更加注重生活的质量,追求更健康,更长寿.因此,开发一个面 ...

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

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

  9. 具有IDE或IDE插件的Spring Boot Initilizr

    This is continuation to my previous post. Before reading this post, please go through my previous po ...

最新文章

  1. S5700三层交换机 复杂网络环境设置默认路优先级实战
  2. 三星emcp型号详解_嵌入式存储产品发展趋势:uMCP取代eMCP序幕拉开
  3. 安全与加密-使用gpg和openssl实现加密与解密
  4. 如何“正确”为SharePoint字段命名
  5. 处理器体系结构(了解CPU的基本运行原理)——《深入理解计算机系统》
  6. ajax存到php变量,Ajax返回值作为PHP变量
  7. rabbitmqctl status报错
  8. 基于神策用户画像,在线教育企业线索标签体系搭建及培育全流程解析
  9. Golang——垃圾回收GC
  10. Asp.net 关于错误提示 类型“XXX1”在未被引用的程序集中定义,必须添加对程序集XXX2的引用...
  11. jzoj6316-djq的朋友圈【状压dp】
  12. LeetCode 334. 递增的三元子序列
  13. ggplot2箱式图两两比较_作图技巧024篇ggplot2在循环中的坑
  14. STM32H743+CubeMX-串口非空闲中断接收
  15. Spring Cloud与微服务学习总结(5)——认证鉴权与API权限控制在微服务架构中的设计与实现(三)
  16. JAVA-SWING:生成透明JTable的改进2
  17. Akka向设备组添加Actor注册《thirteen》译
  18. 【TWVRP】基于matlab遗传和模拟退火算法求解带时间窗的取送货问题【含Matlab源码 1139期】
  19. 世界杯正在成为鸡肋!球迷越来越像傻瓜!
  20. win10强制关闭飞行模式_Win10一键关闭自动更新

热门文章

  1. mysql中怎样扑抓到是那个字段出错_mysql 常见的几个错误问题
  2. svn修改提交路径_使用SVN钩子强制提交日志和限制提交文件类型
  3. isis学不到looback口的路由_使用路由器后测速达不到宽带的网速怎么办?
  4. 阻塞队列 java 源码_Java源码解析阻塞队列ArrayBlockingQueue常用方法
  5. css 水珠动图,CSS3逼真水珠特效
  6. android gridview 间隔线,Android开发之RecyclerView的间隔线处理
  7. Pytorch学习- 小型知识点汇总 unsqueeze()/squeeze() 和 .max() 等等
  8. c++ :: 用法一
  9. vb.net 设置打印纸张与页边距_文字办公—Word文档如何设置装订线
  10. 72. Leetcode 99. 恢复二叉搜索树 (二叉搜索树-中序遍历类)