What is Spring Boot

What is Spring Boot

This will be a short post more focused towards introducing Spring Boot, We will discussWhat is Spring Boot“? and how Spring Boot is helpful in building Java based enterprise applications.

 

Introduction

As a Java developer, it’s very likely that we have worked with Spring Framework based application directly or indirectly.Spring has a number of ways to configure its behavior, it provides the option to use XML based configurations or to use Annotations, JavaConfig is becoming the de facto standard for the new Spring based applications.Although these options seem really good, with large enterprise applications involves hundreds of modules and complicated business rules, these configurations can become really complicated. Below are some of the complications which large application can bring in to the picture

 

  • Each module has its own configurations.
  • Each module contains its own set of dependencies (third-party dependencies)
  • Upgrading application (e.g Spring 4.x to 5.x) will be complicated as we need to ensure that all required dependencies are upgraded correctly.
  • In case some of the dependencies are not working correctly, trying to find out root cause is a large application is really complicated and challenging.

 

All above issues are more or less related to making sure we have everything before dev team can start working on actual tasks. Now let’s talk about another use case which we use to do with any Spring based application, Let’s say we want to create a web-based application, these are most common steps most of us will be doing on regular basis

 

  • Create a web application using Maven or IDE of our choice.
  • Copy standard web application configurations (web.xml configuration for Spring MVC application).
  • Tweak above configurations based on our requirements.
  • Configure Spring MVC standard beans like ViewResolver, MessageSource etc.
  • Configure Database properties to be used for our application.
  • Establish DB layer and ensure underlying DB connection is in place before we can start using it (EntityManagerFactory, TransactionManager etc.)

 

This list can grow significantly based on type of our application

 

 

1. What is Spring Boot

All of the above steps seem very to us but they add a lot of overhead to the development team and instead of focusing on solving the actual business problem, initial time will be consumed to ensure that everything is in the correct place to start work. Think of Spring Boot as a tool which can do these initial tasks for us automatically.Spring Boot works on an opinionated view of the Spring platform being used by us and ensures that team can quickly start working on solving the actual business problem rather than spending time on the initial configurations and setup.

Spring Boot provides the following feature out of the box

    1. It simplifies Spring dependencies by taking the opinionated view ( we will discuss it in more details).
    2. Spring Boot provides a preconfigured set of technologies/framework to reduces error-prone configuration so we as a developer focused on building our business logic rather than thinking of project setup.
    3. You really don’t need those big XML configurations for your project.
    4. Embed Tomcat, Jetty or Undertow directly.
    5. Provide opinionated Maven POM to simplify your configuration

 

Using Spring Boot, it’s easy to manage and handle issues highlighted in the introduction section. .We are not required to manually search for compatible jars during upgrade,  Spring Boot will ensure that our application is upgraded to  the correct version (This is called working on application with minimum fuss)

Let’s take a look at a sample pom.xml for our web application to get an understanding of sample Spring Boot configuration

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.javadevjournal.demo</groupId>
    <artifactId>sample web application</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>
    <name>rWeb Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
</project>

Just pay close attention to <packaging> tag, Spring Boot provides flexibility to run our application as a jar and not forcing us to use war as required packaging type.

2. Better Dependency Management

Just check configuration closely and you won’t be finding any entry for all those Spring dependencies (like web MVC, core, AOP, ORM, Validation API etc.), you might have noticed similar entries spring-boot-starter-*, this is Spring Boot dependency management process. We have added spring-boot-starter-web to our pom.xml and Spring Boot will pull all required dependencies for Spring MVC application (no more manual configurations).

 

 

3. Auto Configurations

Auto Configuration is another interesting feature of Spring Boot this is why Spring Boot team say’s that it has opinions.These are some of work Spring Boot will do for you

  1. It will add all dependencies as highlighted in point 2.
  2. Auto Configurations indicates that Spring Boot has some reasonable defaults i.e based on the configurations Spring Boot will guess the type of application and will supply default implementations required to run your application in case we have not defined those in our application. in case you define these, Spring Boot will ensure that these defaults will be taken out of the context and let your custom configurations will take charge of application.
  3. To give a more clear picture, let’s say you have defined dependency for JPA and have not defined any database configurations, Spring Boot will automatically create required configurations for us. 

 

Read our article on to get the in-depth understanding of Spring Boot Auto Configurations.

 

 

3. Servlet Container

Do you recall that process of deploying your application on the Servlet container (Tomcat etc.), every time we make those small changes and require to deploy those into the app server to test our changes? Spring Boot provides support for embedded Servlet container and we are no longer require to deploy our application on app server (This can be run easily using standard main method) but at the same time we can access our application on the browser using http://<host>:<port>

Spring-boot-starter-web entry in our pom.xml will provide embedded servlet container for our web application, Apache Tomcat is the default servlet container provided by Spring Boot, however, Spring boot provides ways to use other servlet containers (all we have to add the required starter for this).

 

Read our post Building an Application with Spring Boot to start building your application with Spring Boot.

 

 

Summary

In this post, we get an understanding of the Spring Boot, we covered What is Spring Boot? and what are the Benefits of Spring Boot? We discussed different features of the Spring Boot. Spring Boot internally does a lot of things for us which seems to magical to us. In this series, we will be uncovering all these internal details of the Spring Boot.

Leave a Reply

1 Comment on "What is Spring Boot"

Notify of
avatar
Sort by:   newest | oldest | most voted
trackback

[…] What is Spring Boot […]

wpDiscuz