Skip to content

Introducing Spring Boot

Estimated time to read: 3 minutes

From Spring Boot Fundamentals

Getting Started

Spring Boot is an extension of the Spring framework, that assists in removing much of the boilerplate code that characterizes Spring.

Course Scenario

Keysoft are in need of an application that enables them to easily track issues within their applications. This application will be known as TrackZilla.

Trackzilla will use Spring Boot to make development faster and configuration easier. This course will use the scenario to walk through the many different areas of Spring and Spring Boot.

graph LR
    A[TrackZilla] --> B[TrackZilla Controller]
    B[Trackzilla Controller] --> C[Application Service]
    B[Trackzilla Controller] --> D[Ticket Service]
    C[Application Service] --> E[Repository]
    D[Ticket Service] --> E[Repository]
    E[Repository] --> F[Trackzilla H2 Database]

Spring Boot Overview

What is Spring Boot?

Spring Boot sits on top of the Spring framework. It makes it easy to setup and configure Spring applications with minimal fuss.

XML-light

Spring is a lightweight development framework, however, it is highly reliant on the amount of configuration required to upstart a service, by its nature, Spring is also XML based.

Later versions of Spring introduced annotation based configuration to reduce the dependency on XML configuration, though this didn't solve the problem entirely.

Common Structure

When developing a web application, the structure is similar across multiple applications with similar dependencies. For example, a web application typically follows the following structure:

flowchart
    subgraph Servlet Container
    A[Application] --- B[Configuration]
    C[Controller] --> D[Service]
    A --> C
    C --> E[Service]
    D --> F[Repository]
    E --> F
    F --> H[Database]  
    end

The structure above contains much boilerplate. Spring Boot helps solve this problem, by emphasizing convention over configuration and is smart enough to select dependencies and auto-configure what is required by itself.

Simple Deployment

Spring Boot also aids in simplifying the deployment an application and comes with several built-in servlet containers, and embeds directly with no need to deploy WAR files separately.

Features of Spring Boot

Automatic configuration

Automatic Configuration is mainly a time-saving feature. It will automatically configure the application, based on libraries added to the CLASSPATH of the system. If dependencies are included within Gradle or Maven, Spring Boot will automatically configure the application for the specific requirements, as per the file.

Starter Dependencies

A starter dependency is included within a build tool file and acts as a 'one-stop-shop' that includes all of the dependant libraries required. Examples of these are:

  • spring-boot-starter-web
  • spring-boot-starter-test
  • spring-boot-starter-data-jpa
  • spring-boot-starter-thymeleaf

By including the relevant starter dependency, Spring Boot will automatically obtain any required dependencies. For example:

spring-boot-starter-test will include:

  • JUnit
  • Mockito
  • Hamcrest
  • Spring-Core
  • Spring-Test

spring-boot-starter-data-jpa will include:

  • Spring Data JPA with Hibernate
  • JDBC
  • Entity Manager
  • Transaction API
  • Spring Data JPA
  • Aspects

spring-boot-starter-web will include:

  • Web application development
  • Spring MVC
  • REST
  • Tomcat
  • Jackson (JSON to Object Mapping)

Minimum Dependencies

pom.xml
...
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>x.x.x.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>x.x.x.RELEASE</version>
</dependency>

Unlike Spring, Spring Boot only requires one dependency to get a web application up and running.

pom.xml
...
<dependency>
    <groupId>org.springframework.booth</groupId>
    <artifactId>spring-booth-starter-web</artifactId>
    <version>x.x.x.RELEASE</version>
</dependency>

Command Line Interface

The Spring Boot Command Line Interface (CLI) for Spring Boot. This means that an entire application can be written using Groovy scripts... if you are a sadist! The CLI is often used for rapid prototyping.

Actuator

The actuator allows you to see what is happening within a running Spring Boot application. In can show internal runtime operations information about the application.

Applications can be managed using HTTP endpoints or using JMX.

The actuator can show metrics such as:

  • Health Status
  • Metrics
  • Logs
  • Audit events
  • HTTP traces