Notice

╠ This is my personal blog and my posts here have nothing to do with my employers or any other association I may have. It is my personal blog for my personal experience, ideas and notes. ╣

Sunday, July 18, 2021

Introduction to Spring Boot

 History of Spring Boot

Before Spring Boot enterprise-level development creating an application with the Spring framework was so difficult. As a developer, you have to create and maintain the dependence injection, web configuration, deployment and etc. This also increase the learning curve for the developers. 

Mike Youngstrom opened Spring JIRA # SPR-9888 feature JIRA on 17th Oct 2012. The idea was to reduce the learning curve of any new developer who will be coming in to create application using Spring's Web Application.

What is the Spring Boot?

Spring framework provides a pre-setup of Spring and some third party library using which developer could develop an application without any/much of configurations result in faster development.  Non-functional features are readily available such as an embedded server, health check, security, metrics, and externalised configuration. If we want to differ from Spring-provided default configurations we could simply do so. 

Spring Boot application could be bundled into a jar or a traditional war, as a result, it is easy to deploy. It also provides a command-line interface (CLI) to run the Spring script. 


Why anyone uses Spring Boot?

  1. Do prototyping.
  2. Creating a minimum viable product for the actual market. 
  3. Create Microservice 

How to use/implement Spring Boot?

Spring Boot requirements 

  1. Java 8 onwards supported 
  2. Maven 3.3+ version build tool supported
  3. Gradle 6.3+ version build tool supported (5.6.x is also supported but is deprecated form)
  4. Tomcat 9.0 embedded servlet container (Servlet 4.0) supported
  5. Jetty 9.4 embedded servlet container (Servlet 3.1) supported
  6. Undertow 2.0 embedded servlet container (Servlet 4.0) supported

You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.

Spring Boot is available in Groovy or Kotlin or Java language for application development. 

To minimise the developer’s effort Spring provide Spring Initializr (https://start.spring.io/) to generate the basic structure of your project with all the dependency in it. The Spring Boot Command Line Interface (CLI) is a command-line tool that you can use to quickly prototype an application. As it uses Groovy script for it, which means there is no boilerplate code that still has flour of Java.


Creating a simple application

Open Spring Initializr (https://start.spring.io/) to generate the basic structure of your project with all the dependency in it.


This will create the basic project structure. 


pom.xml which is generated from Spring Initializr (https://start.spring.io/). 

Note all the official  starters follow the naming pattern spring-boot-starter-*

It has a spring-boot-starter-parent parent. We included only Spring Web and Spring Initializr add the test for unit testing. We will see how to test Spring Boot in another blog. 





The main class generated by Spring Initializr


Created a controller to make REST call

RestContoller annotation let the Spring know this is a controller class
RequestMapping maps HTTP requests to handler methods of MVC and REST controllers