Step1.Install Java 17
1.Download and Install
Reference: https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
2.Set up the “JAVA_HOME” environment variable to point to your Java 17 installation directory.
3.Check the java version
Open a terminal in VSCode by selecting Terminal > New Terminal from the menu.
And input “java -version”.
$ java -version
java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)
Step2.Create a new Spring Boot project
1.Install “Spring Boot Extension Pack”
This pack contains
- Spring Boot Tools
- Spring Initializr Java Support
- Spring Boot Dashboard
2.Create New Project
3.Specify Spring Boot Version (Latest without SNAPSHOT version is OK).
4.Select project language (Java).
5.Define the Group Id.
6.Define the Artifact Id.
7.Specify the packaging type (Jar).
In case Jar: The Spring Boot application is packaged in single Jar file. For Local or Staging.
In case War: The War file does not include Tomcat. For Production.
8.Specify Java Version (17).
9.Set the dependency library (Spring Web).
10.If opened the explorer, select the directory generate the project.
If click the “Open”, another VScode will be opened for the project.
Step3.Open the Spring Boot project in VSCode
1. SpringBootApplication class should be generated automatically on the project.
Step4.Write and run your Spring Boot application
1.Create Controller- SpringdemoController.java
package com.example.springdemo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringdemoController {
@RequestMapping("/")
public String test() {
return "Hello Spring Boot";
}
}
Step5.Test your Spring Boot application
1.We can test by clicking the Run etc.
2.Access to “http://localhost:8080” from browser, and then we can see the response.