Tutorial

Key Components and Internals of Spring Boot Framework

Published on August 3, 2022
author

Rambabu Posa

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

@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:

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 “https://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 https://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. If you have any queries, please drop me a comment.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Rambabu Posa

author

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
February 9, 2022

Very useful, Thank you for this great post

- Leena

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    May 8, 2019

    I am really excited to say it’s an Excellent Explanation I have understood clearly want to do more knowledge share to like

    - Kishore puja

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      March 30, 2018

      Its very clear and beneficial tutorial for the beginners

      - Gopi Sainadh Aluri

        JournalDev
        DigitalOcean Employee
        DigitalOcean Employee badge
        March 23, 2018

        how spring annotation get works ?. i always confused with spring boot annotation. what mechanism is going on while executing annotation. i have confusion in @Configuration annotation. when it execute and how . please give me explanation . i really confused .

        - Dattatray Sabne

          JournalDev
          DigitalOcean Employee
          DigitalOcean Employee badge
          March 9, 2018

          great! thanks for the help

          - arun singh

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            February 23, 2018

            Its very helpful tutorial. Thanks

            - mohamed lamine

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              December 3, 2017

              Great Article for beginners

              - Abbas

                JournalDev
                DigitalOcean Employee
                DigitalOcean Employee badge
                November 8, 2017

                Very nice for beginners

                - Jyothi

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  October 14, 2017

                  It is very nice and easily understandable tutorial.Thanks

                  - PayalKumar

                    JournalDev
                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    August 12, 2017

                    Thanks for sharing nice tutorial.

                    - Vinayak K

                      Try DigitalOcean for free

                      Click below to sign up and get $200 of credit to try our products over 60 days!

                      Sign up

                      Join the Tech Talk
                      Success! Thank you! Please check your email for further details.

                      Please complete your information!

                      Become a contributor for community

                      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                      DigitalOcean Documentation

                      Full documentation for every DigitalOcean product.

                      Resources for startups and SMBs

                      The Wave has everything you need to know about building a business, from raising funding to marketing your product.

                      Get our newsletter

                      Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

                      New accounts only. By submitting your email you agree to our Privacy Policy

                      The developer cloud

                      Scale up as you grow — whether you're running one virtual machine or ten thousand.

                      Get started for free

                      Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

                      *This promotional offer applies to new accounts only.