Boot

Spring Boot 3 Overview

Hello. In this tutorial, we will take a look at the Spring Boot 3 overview.

You can also check this tutorial in the following video:

Spring Boot 3 Tutorial – Video

1. Introduction

Spring Boot 3 and Spring 6 is the recent development in the spring world where out-of-box support for native java compilation is added and all the deprecated features are removed. Spring boot 3 provides support for different features that were added –

  • Updating base line java version to Java 17
  • Replacing Java EE with Jakarta EE
  • Support for Java Platform Module System (JPMS)
  • Enhanced support for native compilation; thus making use of cloud-native applications efficient
  • Observability in spring
  • Support for Project Loom
  • Native support for declarative HTTP client

2. Spring Boot 3 Overview

Let us dive into some practice stuff and I am hoping that you are aware of the Spring and Spring Boot basics.

2.1 Tools Used for Spring boot application and Project Structure

We are using IntelliJ, JDK 17, and Maven. In case you’re confused about where you should create the corresponding files or folder, let us review the project structure of the spring boot application.

Fig. 1: Project structure

Let us start building the application!

3. Creating a Spring Boot application

To create the base for this application I will be skipping the traditional approach of creating the project and will move toward the Spring Initializr which offers the quickest way to set up the project. To create this tutorial I will be exploring Maven as the project and Java as the programming language.

3.1 Importing the project

Once the project setup is done via the Spring Initializr import it into IntelliJ. The imported project will automatically download the jars specified in the pom.xml. For this tutorial, I will use the spring-boot and Lombok dependencies for creating the application.

3.2 Creating the implementation files

You can download the complete application from the Downloads section.

3.2.1 Setting the properties

Create a properties file in the resources folder and add the following content to it. The file will contain information about the port number on which the application should run. You’re free to change this information as per your needs.

application.properties

server.port=9300

3.2.2 Creating the Greeting model class

Create the model class responsible to return the greeting response.

Greeting.java

package com.example.demo.model;

import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Greeting {

  UUID id;
  String message;
}

3.2.3 Create the Controller class

The controller will be responsible to handle the client interactions. The application exposes the HTTP GET endpoint to show a welcome message to the user.

GreetingController.java

package com.example.demo.api;

import com.example.demo.model.Greeting;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@Slf4j
public class GreetingController {

  @GetMapping(value = "/")
  public ResponseEntity<Greeting> welcome() {
    log.info("welcome endpoint triggered");
    Greeting greeting = new Greeting(UUID.randomUUID(), "hello-world");
    return ResponseEntity.status(200).body(greeting);
  }
}

3.2.4 Creating an implementation class

Creating an implementation class responsible to start the Spring application.

Springboot3HelloworldApplication.java

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Springboot3HelloworldApplication {

  public static void main(String[] args) {
    SpringApplication.run(Springboot3HelloworldApplication.class, args);
  }
}

4. Run the main class and Demo

To run the application, right-click on the Springboot3HelloworldApplication.class class, Run As -> Spring Boot App. If everything goes well the application will be started successfully on a port number – 9300.

Application endpoints

// Welcome endpoint
localhost:9300/api/

To test the application open the browser and hit the above url. A hello world response will be shown.

Fig. 2: Application output

That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!

5. Summary

In this tutorial, we understood spring 6 and spring boot 3 with a small practice implementation. You can download the sample application as an Eclipse project in the Downloads section.

6. Download the Project

This was an example of understanding spring boot 3 practical application.

Download
You can download the full source code of this example here: Spring Boot 3 Overview

Yatin

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button