Introduction to Spring Boot

Abhishek Jindal
3 min readJun 22, 2021

--

What is Spring ?

A lightweight alternative to Java EE in terms of component code. It utilizes dependency injection and Aspect oriented programming to achieve capabilities of EJB (Enterprise Java Beans) with POJOs (Plain Old Java Objects). It handles infrastructure so that developer can focus on application and business logic.

Evolution of Spring:

  1. Spring 2.0 was configured with custom XML namespaces.
  2. Spring 2.5 introduced annotation based component scanning — such as @Component and @Autowired annotations.
  3. Spring 3.0 introduced Java based configuration alternative to XML — @Enable-prefixed annotations completely removing XML configuration.
  4. Spring 4.0 unleashed support for conditional configuration, runtime decisions determine which configuration would be used and which will be ignored.
  5. Spring 5.0 added support for reactive programming and which is a significant paradigm shift and baseline support for java 8.

What were the issues with Spring?

In order to write a simple Hello World Web Application, we would require -

  1. A project structure with Maven or Gradle build file including required dependencies.
  2. A web.xml file that declare Spring’s DispatcherServlet.
  3. A Spring Configuration that enables Spring MVC.
  4. A controller class that will respond to requests with “Hello World”.
  5. A web Application server, such as Tomcat, to deploy the application.

A lot of boiler plate code has to be written and maintained in order to create a simple REST controller that returns a “Hello World” message thus increasing developer’s effort towards application configuration over business logic.

Advantages of Spring Boot? What does it bring to the table?

  1. Automatic Configuration

Spring Boot automatically provides configuration for application functionality common to many Spring Applications. If Spring Boot detects that there is a library (for example — Security, JPA, H2, Thymeleaf, Spring MVC) in application class path, it automatically configures it. No need to explicitly declare beans and provide boilerplate code.

2. Starter Dependencies

Just tell Spring Boot what kind of functionalities are needed and it will ensure that the libraries are added to the build. It helps with project dependency management by providing special Maven/Gradle dependencies that take advantage of transitive dependency resolution. Also, there is no need to worry about versions of the libraries needed since the libraries pulled by starters are tested together.

3. Command line interface

Optional feature of Spring Boot lets write complete applications with just application code. No need of traditional project build. It leverages starter dependencies and auto-configuration to let the user focus on writing code. No need for import statements as the cli detects what dependencies are required and adds them onto class path. Once those dependencies are added, auto-configuration kicks in and ensures DispatcherServlet and Spring MVC are enabled so that the controller can response to HTTP requests.

4. Actuator

Spring Boot Actuator gives insight into what is going on inside of a running spring boot application. It offers ability to inspect application at runtime that include -

  1. What beans have been configured in Spring Application context.
  2. What decisions were made by Spring’s auto-configuration.
  3. What environment variables, system properties, configuration properties, and command line arguments are available to your application.
  4. The current state of the threads in and supporting the application.
  5. A trace of recent HTTP requests handled by the application.
  6. Various metrics pertaining to memory usage, garbage collection, web requests and data source usage.

What Spring Boot is NOT?

  1. Spring Boot is not an Application Server. It accomplishes this by embedding a servlet container (tomcat, jetty, undertow) within the application.
  2. Spring Boot does not implement Java Specifications such as JPA or JMS.
  3. Spring Boot does not employ any code generation to accomplish auto-configuration.

--

--

Abhishek Jindal

SWE at Edifecs, Technology Enthusiast, Art admirer and creator.