原文地址: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.

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.

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.

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.

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.

Key Components and Internals of Spring Boot Framework--转的更多相关文章

  1. spring boot面试问题集锦

    译文作者:david  原文链接:https://www.javainuse.com/spring/SpringBootInterviewQuestions Q: 什么是spring boot? A: ...

  2. 面试那点小事,你从未见过的spring boot面试集锦(附详细答案)

    一, 什么是spring boot? 多年来,随着新功能的增加,spring变得越来越复杂.只需访问页面https://spring.io/projects,我们将看到所有在应用程序中使用的不同功能的 ...

  3. Complete Guide for Spring Boot Actuator

    You are here to learn about Spring Boot Actuator for collecting metrics about your production grade ...

  4. Spring Boot 2.X(六):Spring Boot 集成Redis

    Redis 简介 什么是 Redis Redis 是目前使用的非常广泛的免费开源内存数据库,是一个高性能的 key-value 数据库. Redis 与其他 key-value 缓存(如 Memcac ...

  5. 面试 Spring Boot 再也不怕了,答案都在这里!

    问: 什么是spring boot? 答:多年来,随着新功能的增加,spring变得越来越复杂.只需访问页面https://spring.io/projects,我们将看到所有在应用程序中使用的不同功 ...

  6. step6----->往工程中添加spring boot项目------->修改pom.xml使得我的project是基于spring boot的,而非直接基于spring framework

    文章内容概述: spring项目组其实有多个projects,如spring IO platform用于管理external dependencies的版本,通过定义BOM(bill of mater ...

  7. 【redis】5.spring boot项目中,直接在spring data jpa的Repository层使用redis +redis注解@Cacheable直接在Repository层使用,报错问题处理Null key returned for cache operation

    spring boot整合redis:http://www.cnblogs.com/sxdcgaq8080/p/8028970.html 首先,明确一下问题的场景 之前在spring boot整合re ...

  8. Spring Boot之从Spring Framework装配掌握SpringBoot自动装配

    Spring Framework模式注解 模式注解是一种用于声明在应用中扮演“组件”角色的注解.如 Spring Framework 中的 @Repository 标注在任何类上 ,用于扮演仓储角色的 ...

  9. 【Redis系列】Spring boot实现监听Redis key失效事件

    talk is cheap, show me the code. 一.开启Redis key过期提醒 方式二:修改配置文件 redis.conf # 默认 notify-keyspace-events ...

随机推荐

  1. [转]Navicat for MySQL快捷键

    Navicat for MySQL快捷键 ctrl+q 打开查询窗口 ctrl+/ 注释sql语句 ctrl+shift +/ 解除注释 ctrl+r 运行查询窗口的sql语句 ctrl+shift+ ...

  2. ios图片添加文字或者水印

    在项目中,我们会对图片做一些处理,但是我们要记住,一般在客户端做图片处理的数量不宜太多,因为受设备性能的限制,如果批量的处理图片,将会带来交互体验性上的一些问题.首先让我们来看看在图片上添加文字的方法 ...

  3. 12G服务器在BIOS中收集阵列卡日志(TTY日志)的方法

      如果系统进不去.请参考如下方法收集日志. 请准备个U 盘,容量在8G以下(含8G),否则会识别不到. 图片参考,以描述为准 F2 enter BIOS option--> Enter the ...

  4. wpf下datagrid使用过程中需要注意的几点(一)

    MainWindow.xaml中的代码如下: <DataGrid CanUserAddRows="False" ItemsSource="{Binding}&quo ...

  5. Android 客户端设计之解决方案

    解决方案,是正对与需求来谈的.一个抽象的需求,需要一个较为上层抽象的解决方案来处理,这是病和药的关系.但是一个解决方案,可能会包含多个功能,每个功能都是解决方案上的一个节点.一个优秀的解决方案必然需要 ...

  6. 对InvokeAction简略分析了解验证失败为什么Action还会继续执行

    一.前言 有些同学使用AuthorizationFilter来进行用户是否登录验证,如果未登录就跳到登录页. 很简单的一个场景,但是有些同学会发现虽然验证失败了,但是整个Action还会执行一遍. 于 ...

  7. Blend 2015 教程 (一) 基础

    微软公司在Visual Studio 2015产品套件中作出了许多革命性的变更,包括.NET开源,.NET服务器端部分跨平台,推出向个人和小团队免费的社区版,移动应用开发部分跨平台支持,商店应用支持C ...

  8. 一个老菜鸟所理解的UX及产品流

    从事前端开发到目前为止已经有4年多的时间了,从一个小菜鸟一路依靠自学,到目前总算一个老菜鸟了.当然了,从事前端的工作,是免不了要对产品以及用户体验有些许了解的.最近谈论起这方面的内容,就按照自己的想法 ...

  9. Oracle建表脚本记录

    --删除 drop table dianfei; --创建表 create table dianfei ( uon ) not null, mmonth ) not null, ddf ,) not ...

  10. 说说设计模式~建造者模式(Builder)

    返回目录 建造者模式是我的"设计模式"里创建型模式里的最后一篇,这种模式在实现中,很多架构都用到了,如MVC,MVP,MVVM,它们都是有建造者模式的精髓的,即,创建与表现分享,我 ...