Getting Started with Spring Boot

In this article, we will discuss what is Spring Boot, what are its goals, key features, create a simple Spring boot application, spring boot advantages etc.

What is Spring Boot?

Spring Boot is a brand new framework from the team at Pivotal, designed to simplify the bootstrapping and development of a new Spring application. The framework takes an opinionated approach to configuration, freeing developers from the need to define a boilerplate configuration. It provides defaults for code and annotation configuration to quick start new Spring projects within no time.
We can use Spring Boot to create Java applications that can be started by using java -jar or more traditional war deployments. We also provide a command line tool that runs “spring scripts”.

Spring Boot Primary Goals

  • Provide a radically faster and widely accessible getting-started experience for all Spring development.
  • Be opinionated out of the box but get out of the way quickly as requirements start to diverge from the defaults.
  • Provide a range of non-functional features that are common to large classes of projects (such as embedded servers, security, metrics, health checks, and externalized configuration).
  • Absolutely no code generation and no requirement for XML configuration.

Key Spring Boot features

Let me a list of few key features of Spring boot framework and we will discuss each key feature briefly.

  • Spring Boot starters
  • Spring Boot autoconfiguration
  • Elegant configuration management
  • Spring Boot actuator
  • Easy-to-use embedded servlet container support

Spring Boot Starters

Spring Boot offers many starter modules to get started quickly with many of the commonly used technologies, like SpringMVC, JPA, MongoDB, Spring Batch, SpringSecurity, Solr, ElasticSearch, etc. These starters are pre-configured with the most commonly used library dependencies so you don’t have to search for the compatible library versions and configure them manually.
For example, the spring-boot-starter-data-jpa starter module includes all the dependencies required to use Spring Data JPA, along with Hibernate library dependencies, as Hibernate is the most commonly used JPA implementation.
Read more about starters on Important Spring boot Starters with Examples

Spring Boot Autoconfiguration

Spring Boot addresses the problem that Spring applications need complex configuration by eliminating the need to manually set up the boilerplate configuration.
Spring Boot takes an opinionated view of the application and configures various components automatically, by registering beans based on various criteria. The criteria can be:
  • Availability of a particular class in a classpath
  • Presence or absence of a Spring bean
  • Presence of a system property
  • An absence of a configuration file
For example, if you have the spring-webmvc dependency in your classpath, Spring Boot assumes you are trying to build a SpringMVC-based web application and automatically tries to register DispatcherServlet if it is not already registered. If you have any embedded database drivers in the classpath, such as H2 or HSQL, and if you haven’t configured a DataSource bean explicitly, then Spring Boot will automatically register a DataSource bean using in-memory database settings.
You will learn more about the autoconfiguration on What is Spring Boot Auto Configuration?

Elegant Configuration Management

Spring supports externalizing configurable properties using the @PropertySource configuration. Spring Boot takes it even further by using the sensible defaults and powerful type-safe property binding to bean properties. Spring Boot supports having separate configuration files for different profiles without requiring many configurations.

Spring Boot Actuator

Being able to get the various details of an application running in production is crucial to many applications.The Spring Boot actuator provides a wide variety of such production-ready features without requiring developers to write much code. Some of the Spring actuator features are:
  • Can view the application bean configuration details
  • Can view the application URL mappings, environment details, and configuration parameter values
  • Can view the registered health check metrics
Read more about Spring Boot Actuator on Spring Boot Actuator

Easy-to-Use Embedded Servlet Container Support

Traditionally, while building web applications, you need to create WAR type modules and then deploy them on external servers like Tomcat, WildFly, etc. But by using Spring Boot, you can create a JAR type module and embed the servlet container in the application very easily so that the application will be a self-contained deployment unit. Also, during development, you can easily run the Spring Boot JAR type module as a Java application from the IDE or from the command-line using a build tool like Maven or Gradle.

System Requirements

Spring Boot 2+ requires Java 8 or 9 and Spring Framework 5.1.0.RELEASE or above.
Explicit build support is provided for the following build tools:

Servlet Containers

Spring Boot supports the following embedded servlet containers:
You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.

Installing Spring Boot with Maven and Gradle


I have written a separate article for how to install Spring boot with maven and gradle.

Developing your First Spring Boot Application

I have written a separate article for how to develop Spring boot hello world application step by step on Spring Boot - Building a RESTful Web Service
Once you will develop simple Spring boot REST API using the above article then learn to create CRUD REST APIs using below articles.

Spring Boot REST API Development Articles

>> Spring Boot 2 + Jersey REST + JPA + Hibernate 5 CRUD REST APIs Example
Finally, we will list of all the advantages of Spring Boot framework here.

Advantages of Spring Boot

  • It is very easy to develop Spring Based applications with Java.
  • It reduces lots of development time and increases productivity.
  • It avoids writing lots of boilerplate Code, Annotations and XML Configuration.
  • It is very easy to integrate Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
  • It follows “Opinionated Defaults Configuration” Approach to reducing Developer effort
  • It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test our web applications very easily.
  • It provides CLI (Command Line Interface) tool to develop and test Spring Boot(Java or Groovy) Applications from command prompt very easily and quickly.
  • It provides lots of plugins to develop and test Spring Boot Applications very easily using Build Tools like Maven and Gradle
  • It provides lots of plugins to work with embedded and in-memory Databases very easily.

References

I have written 35+ articles on Spring boot, you can visit on Spring Boot Tutorial

Comments