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.

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)