Introduction to Spring Boot

Spring Boot can help us create Spring applications much faster than otherwise. Spring Boot is based on "conventions over configuration" and you have to do very little in configuring an application. For example, you can create a web application with an embedded server in few minutes and you can "just run" them like a desktop application. 

Spring boot home page @ https://projects.spring.io/spring-boot/ describe itself as follows:

Spring boot takes an opinionated view of the Spring platform and third-party libraries, for building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run", so that you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

Important features, as listed, are:

  1. Create stand-alone Spring applications

  2. Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

  3. Provide opinionated 'starter' POMs to simplify your Maven configuration

  4. Automatically configure Spring whenever possible

  5. Provide production-ready features such as metrics, health checks and externalized configuration

  6. Absolutely no code generation and no requirement for XML configuration

 

Spring Boot is just a convenient way to do Spring and hence the more you know Spring, the better you will understand Spring boot.

 

Important Features of Spring Boot

  1. Promotes container less deployment. The container (e.g. Apache Tomcat) is embedded within your application and you can run your application anywhere with just Java (e.g. a cloud server). You can also deploy your Spring boot applications to standard containers.

  2. Provides easy to use starter pom dependencies such as spring-boot-starter, spring-boot-starter-test, spring-boot-start-web etc. which inturn includes lot of required dependencies based on the context.

  3. Provides many ways to configure the Spring application. Spring Boot allows you to externalize configurations by using an application.properties or application.yml file. Spring Boot allows you to configure and use features such as using JMX, profiles, logging etc. easily.

  4. Provides out-of-the-box NFRs through the Spring Boot Actuator. Auditing, health and metrics gathering can be automatically applied to your application. You can choose to manage and monitor your application using HTTP endpoints, with JMX or even by remote shell (SSH or Telnet).

 

Starter POMs

Spring Boot starter poms (e.g. spring-boot-starter-web) add all dependencies for a particular use case (e.g. web app) and provide default configurations. 

There are various starter pom dependencies such as spring-boot-starter, spring-boot-starter-web and spring-boot-starter-jdbc etc.

 

SpringApplication.run()

The main method is the starting point of execution to a Spring Boot application, even if it is a web application. SpringApplication.run() method is responsible for starting spring, creating spring context, applying annotations and setting up container. You may refer to the Quick Start section @ https://projects.spring.io/spring-boot/ for an example.

 

@SpringBootApplication

@SpringBootApplication annotation is commonly used for a Spring Boot main class, as it wraps other annotations including @Configuration, @EnableAutoConfiguration and @ComponentScan.

 

Spring Initializr - start.spring.io

You can go to the link https://start.spring.io/ and configure and create a Spring Boot project with all required dependencies.

You can also use an IDE that provides Spring Boot support such as Spring STS or Intellij IDEA, which internally connects to start.spring.io. With Intellij IDEA IDE, you can go to create new project and on the first page of the New Project wizard, select Spring Initializr in the left pane.

 

Spring Boot CLI

Spring Boot ships with a command line tool (Spring Boot CLI) that can be used if you want to quickly prototype with Spring. It allows you to run Groovy scripts. You can install it by following notes here. Spring Boot CLI also internally connects to start.spring.io.

You can create a spring boot application MyABCAppln with a starter-web dependency as:

./spring init –dependencies=web MyABCAppln.

 

Spring Boot Samples

Spring also provides a set of sample Spring boot applications in their github repo. Find more @ https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples. Just clone and use them.

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!