Spring Boot 3

Spring Boot 3

World Before Spring Boot

  • Setting up Spring projects before Spring boot was not easy.

  • We needed to configure a lot of things before we had a production-ready application.

What we had to do before Spring boot came into the picture?

1) Dependency Management(pom.xml)

  • we had to create a pom.xml file with all the dependencies and versions in there.

  • if we had to write tests we had to import the spring test frame work, we had to import Junit, Mockito and manage all those versions.

2) Define web app Configuration(web.xml)

  • if we wanted to make use of Spring MVC we had to configure a dispatcher servelt.

3) Spring configuration(manage spring bean i.e context.xml)

  • we needed to define component scan. If we are building a web application we had to define a view resolver. If we are building a database-related application we need to define a data source, so there is a lot of configuration that we had to do before we had a production-ready application.

4) NFR's(non functional requirements)

  • our application needs to have logging, good error handling and good monitoring in production and we need to be able to look at metrics for our application in production. We had to configure all these before spring boot and this took a lot of time for us to be able to deliver the application.

AND WE HAD TO REPEAT THIS FOR EVERY NEW PROJECT.

What is a spring boot?

Spring Boot provides a good platform for Java developers to develop a stand-alone and production-grade spring application that you can just run. You can get started with minimum configurations without the need for an entire Spring configuration setup.

Advantages of Spring Boot

  • Easy to understand and develop spring applications.

  • Increased productivity.

  • Reduces development time.

Why do we use Spring Boot?

  • It provides a flexible way to configure Java Beans, XML configurations, and Database Transactions.

  • It provides powerful batch processing and manages REST endpoints.

  • In Spring Boot, everything is auto-configured; no manual configurations are needed.

  • It offers an annotation-based spring application

  • Eases dependency management

  • It includes Embedded Servlet Container

Spring Boot Starters

Handling dependency management is a difficult task in very big projects. Spring Boot resolves this problem by providing a set of dependencies for the developer's convenience.

Let's say, for example, you want to use Spring and JPA for database access, it is sufficient if you include the spring-boot-starter-data-JPA dependency in your project.

Examples

Let's look at the following Spring Boot starters explained below for a better understanding.

Spring Boot Starter Actuator dependency is used to monitor and manage our application. Its code is shown below −

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Spring Boot Starter Security dependency is used for Spring Security. Its code is shown below −

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
</dependency>

Spring Boot Starter web dependency is used to write the Rest Endpoints. Its code is shown below −

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Spring Boot Starter Thyme Leaf dependency is used to create a web application. Its code is shown below −

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

Spring Boot Starter Test dependency is used to write Test cases. Its code is shown below −

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
</dependency>