Home » Enterprise Java » spring » Boot » What is Spring Boot ?

About Santosh Balgar

Santosh Balgar
He is a Software Engineer working in an industry-leading organization. He has completed his bachelors from Visweswaraya Technological University. In his career, he has worked in designing and implementing various software systems involving Java/J2EE, Spring/ Spring Boot, React JS, JQuery, Hibernate and related database technologies. He loves to share his knowledge and always look forward to learning and explore new technologies. He loves to spend his free time with his family. He enjoys traveling and loves to play cricket.

What is Spring Boot ?

In this post, we feature a comprehensive article explaining what is Spring Boot.

Java is a ubiquitous language and Spring/ Spring Boot has become default frameworks of choice for Java Web developers. Spring is one of the market-leading frameworks for building web and enterprise applications.

With the rise of the Spring framework there comes a lot of hurdle in configuring it. Even though Spring is quite flexible with this matter, integrations with different other frameworks made it tedious and erroneous. To handle this fuss Spring Boot was created.

Spring Boot makes it easy to create stand-alone, production-grade Spring applications. It takes Spring and third-party application’s opinionated views and enables us to get started with minimal fuss with configurations.

1. What is Spring Boot

Spring Boot is a Java-based application (Stand-alone, microservices, web) development framework. It is developed and maintained by the Pivotal team. Spring Boot enables developers to build production-grade applications quickly with its auto-configuration ability without losing a lot of time around Spring configurations.

2. Differences between Spring and Spring Boot

Understanding the differences between Spring and Spring boot is important before choosing between them. In this section, we will see how Spring Boot is different than the already existing Spring framework.

As said earlier Spring Boot is built on top of Spring framework. They work together to get the job done.

  • Spring framework was built keeping flexibility in mind to enable developers to integrate with different frameworks. With the advent of newer frameworks, rightly configuring them became a fuss. Whereas Spring Boot’s primary focus is on reducing the configuration and code so that developers can focus more on the crucial parts of their application.
  • Spring Boot provides an auto-configuration facility (tries to automatically configure the application based on the jars added).
  • Spring Boot comes with an embedded web server. This makes local development environment hassle-free and developers don’t have to worry about configuring development web servers in their machines.

3. Is prior knowledge of Spring necessary?

Though many people feel prior knowledge of Spring is not essential, I feel having an idea of Spring Framework gives a strong foundation in learning Spring Boot. The framework itself is built on top of Spring to overcomes the problems faced.

4. Notable features

Spring boot comes with several feature enhancements. In this section, we are going to see some of the notable features.

  • Autoconfiguration – Autoconfiguration feature eliminates the boilerplate code used to configure some of the popular libraries. For example, in traditional Spring application to integrate the H2 in-memory database and Hibernate, a separate data source configuration JDBC template bean to be defined. However, Spring Boot auto detects H2 driver and Hibernate jars and auto-configures the data source. This eliminates data source related configuration code. Spring Boot can make 200+ such decisions and can do auto configurations just by looking at the jar inclusions. Auto-configuration is disabled by default. You can enable auto-configuration using annotation @EnableAutoConfiguration or @SprinBootApplication
  • Starter POM – Starter POM enables our application to find and add common dependencies. It removes a lot of hassle around fining various jars and keeping them up to date with different library versions. By adding spring-boot-starter-web dependency in the pom, we can bring in the minimum dependencies required for Spring Web applications to work.
  • Actuator – With a lot of abstraction in place it becomes harder to debug and getting to know what is happening under the hood. Spring Boot Actuator solves this hurdle. The actuator provides metrics and insights into running the Spring Boot application. It allows us to see Spring Beans configured, Acuto configuration decisions, Environment variables, Command-Line arguments, System configurations and many more. It also enables us to see HTTP request traces, CPU and memory usage, garbage collection, data source usage and so on. Spring Boot Actuator provides various REST endpoints to fetch these data.
  • Spring Boot Initializer – Spring Boot actuator enables us to create an initial structure of the project. Spring initializer can be accessed at Spring Initializer. Go to this website, enter all the metadata and dependencies, then download the project structure as a zip file. Later this can be imported as a Maven/Gradle project.
  • Spring Boot CLI – This is an optional feature and one needs to install Spring Boot CLI explicitly. CLI is a command-line based interface and lets us create Spring Boot application using Groovy programming language. Spring Boot CLI leverages on auto-configuration and starter poms.

5. Why Spring Boot is so popular?

Spring Boot’s popularity is on the rise because it lets us focus on writing application code by eliminating the hassles in the setup process like project structure, configuration, and dependency management. It is opinionated and provides great support for Microservices based architecture. Notably, Spring Boot Actuator provides very granular metrics, this can be very helpful in managing microservices.

6. Disadvantages

So far we have seen what makes Spring Boot a framework of choice. In this section let us see some pitfalls of this framework.

  • We may not need all the dependencies introduced by stater POM always. This will increase the application binary size.
  • As spring boot abstracts many configurations, getting the fine-grained control can be cumbersome sometimes. This might even make the debugging difficult.
  • Larger the application, more the startup time. This might cause problems in a serverless environment.
  • Dependencies increase the use of reflection. This might create a memory footprint to often resulting in failures with Out Of Memory.

7. Monitoring Spring Boot Applications

The module spring-boot-actuator provides production-ready monitoring features. By adding the dependency spring-boot-starter-actuator in pom, enables the actuator feature.

Spring boot actuator provides several ready to use REST endpoints to fetch the metrics of a running application. You can add your own endpoints aswell. Each individual endpoints can be enabled or disabled. Endpoints can be served via either HTTP or JMX.

Some of the actuator endpoints are listed below,

API EndpointDescription
beansDisplays a list of all the beans in your application
auditEventsExposes all the audit events for the current application
cachesExposes all the caches in the application
conditionsShows conditions that were evaluated on configuration and auto configurations
configpropsDisplays a list of all @ConfigurationProperties
envExposes properties from Spring’s ConfigurableEnvironment
flywayShows the flyway migrations that have been applied
healthShows application health information
httptraceDisplays HTTP trace information
infoDisplays applications arbitrary information
integrationgraphShows the spring integration graph. requires spring-integration-core dependency
loggersShows and modifies logging configuration
liquibaseShows any liquibase migration applied
metricsShows the current application’s metrics
mappingsShows a list of @RequestMapping
scheduledtasksDisplays a list of scheduled tasks in the application
sessionsEnables us to retrieve and delete sessions
shutdownLets the application shutdown gracefully
threaddumpPerforms a thread dump

If the application is a web application then below additional endpoints are available,

API EndpointDescription
heapdumpReturns current heapdump
jolokiaExposes JMX beans over HTTP and it requires jolokia-core dependency
logfileReturns the contents of the log file
prometheusExposes the metrics in a format that can be scraped by Prometheus server. This requires micrometer-registry-prometheus dependency.

By default endpoints except shutdown are enabled. To enable or disable any endpoint management.endpoints.<endpoint id>.enabled = true/false. To make endpoints to be enabled or disabled individually, you need to set management.endpoints.enabled-by-default = false.

8. Example

In this section, I am going to show how easily a spring boot application can be created from Spring Initializer. Also, I am going to show how to access actuator endpoints.

To create the sample Spring Boot application by visiting Spring Initializer and choose the dependencies you need. I have chosen dependencies in the below image,

What is Spring Boot - Spring Starter
Spring Starter

Run the application attached in the download section. Visit endpoint http://localhost:8080/hello to access the hello world endpoint. The output is as below,

What is Spring Boot - Hello World REST
Hello World REST endpoint

Since I have added actuator dependency, the actuator is enabled by default. To see actuator endpoints access http://localhost:8080/actuator. The output is as below.

{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"beans":{"href":"http://localhost:8080/actuator/beans","templated":false},"caches-cache":{"href":"http://localhost:8080/actuator/caches/{cache}","templated":true},"caches":{"href":"http://localhost:8080/actuator/caches","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8080/actuator/info","templated":false},"conditions":{"href":"http://localhost:8080/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:8080/actuator/configprops","templated":false},"env":{"href":"http://localhost:8080/actuator/env","templated":false},"env-toMatch":{"href":"http://localhost:8080/actuator/env/{toMatch}","templated":true},"loggers":{"href":"http://localhost:8080/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:8080/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:8080/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:8080/actuator/threaddump","templated":false},"metrics":{"href":"http://localhost:8080/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:8080/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:8080/actuator/scheduledtasks","templated":false},"mappings":{"href":"http://localhost:8080/actuator/mappings","templated":false}}}

For example, when you access http://localhost:8080/actuator/health you see the below output,

What is Spring Boot - Health endpoint
Health endpoint output

You can try different actuator endpoints to get more idea on actuators.

9. Download the Source code

I have used IntelliJ Idea IDE to create and run this project. It works in Java 8 or above. Use any REST testing utilities like PostMan or any chrome extensions to test the different endpoints.

Download
You can download the full source code of this example here: What is Spring Boot ?

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments