Setup Spring Boot 5.x.x Application Using Java 11.0
What is Spring Boot?
An open source Java-based framework called Spring Boot is used to build micro Services. The Pivotal Team created it, and it’s used to create standalone, production-ready spring apps. You will learn about Spring Boot in this article and become familiar with some of its fundamental ideas. There are 2 ways to create spring boot application.
- Using Spring Boot initializr
- Using an IDE (Here I’m using IntelliJ)
Pre-requisites
-Java — 11 (configured in intelliJ)
-Spring Boot 5 (spring-boot-starter-parent — 2.7.8). This version is compatible with only Java 11 version. If you want to create Spring Boot 6.x.x version you need to install Java 17 or higher version.
-IntelliJ IDEA 2021.3.2 (Ultimate Edition)
How to Create a Spring Boot Application using Spring Boot Initializr?
-Go to https://start.spring.io/ and add following details to the spring initializr.
-In here initially add relevent spring web dependencies (Here I’m adding only spring web dependency) and click ‘Generate’. You will get the zip file as a downloaded file.
-Unzip and open the project in intelliJ.
How to Create the Spring Boot Application Using IntelliJ?
-Download and Install intelliJ 2021.3.2 (Ultimate Edition), You can use any version.
-Click File -> New -> Project and add following details.
-Click ‘Next’ and add initial dependencies.
-Click ‘Finish’
Modify the pom.xml
Once the spring boot application is opened in intelliJ it will look like below structure.
Once you open it in intelliJ, need to do few modifications to the pom.xml. Below I have added the modified the pom.xml. Compare with initial pom.xml and add relevent dependencies.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>OnlineBookStore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>OnlineBookStore</name>
<description>OnlineBookStore</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</build>
</project>
Let’s go through in detail about above dependencies. All versions are in latest versions and compatible with Spring 5.x.x.
- This is for Spring 5.x.x,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
2. These are project details,
<groupId>com.example</groupId>
<artifactId>OnlineBookStore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>OnlineBookStore</name>
<description>OnlineBookStore</description>
3. Java Version,
<properties>
<java.version>11</java.version>
</properties>
4. For maven plugin,
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
5. To run an application’s unit tests, utilize the Surefire Plugin during the test stage of the build lifecycle.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
6. Other Spring Boot dependencies are default dependencies which are added by Spring Boot initializr.
Now all codes are added to the project. Then open maven tool window and run following command
mvn clean install
You will get similar message like above image.
Up the Server
Click following icon in intelliJ.
You will get a message similar to below image.
Now you are ready to implement the Spring Boot Application.
IntelliJ Settings
For your reference I’m adding IntelliJ setting here.