How to Build Spring Boot Project in VSCode?

Creating a Spring Boot project in Visual Studio Code (VS Code) streamlines the Java development experience. In this article, we’ll explore the steps to set up and build a Spring Boot project in VS Code, ensuring a solid foundation to start developing robust applications.

Step by Step process to the Build a Spring Boot Project in VS Code

Step 1: Ensure that the Java Development Kit(JDK) is installed on the computer system and download and install the Visual Studio Code if not already installed.

Step 2: Install the Java Extension pack and Spring Initializer and Spring Development Tool extension of the VS Code.

Install the Spring Initializr Java Support extension in the VS Code.


Install the Spring Boot Tools extension in VS Code.


Install the Spring Boot Extension pack extension in VS Code.


Step 3: Now, we can open the VS Code and access the Command Palette using the shortcut(Ctrl+shift+P).

type "Spring Initializr: Generate a Maven Project" and enter it.


Step 4: We can choose the version of the Spring Boot application.


Step 5: We can enter the project metadata like the Group, Artifact, Name, Description of the Spring application.

Artifact Id:


Group Id:


Choose the language: Java


Select the Version of the Java


Step 6: We can select the required dependencies needed for the project.

Example: Spring Web, Lombok, Spring DevTools


Step 7: Finally, we can choose the location to the generate the project and click the Generate option to generate the Spring Project.


Step 8: We can open the generated project folder in the VS Code application.


Step 9: Open the main class the add the simple controller method of the Application.

Java
package com.example.demoexample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoexampleApplication {

    @GetMapping("/hello")
    public String check() {
        return "Hello World";
    }

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

}


Step 10: We can run the application then it will start at port 8080.


Step 11: We can verify the application is running by the accessing the configuration the local server URL.

http://localhost:8080/hello

Output:

By the following the above steps, we can effectively setup, configure and run the Spring Boot project within the Visual Studio Code. It is leveraging its powerful features for the efficient Java development.

Frequently Asked Questions

How do I add the additional dependencies after the creating project?

We can add the dependencies by the modifying the pom.xml file and add the dependency code snippet within the <dependencies> section of the project.

How can I build and the package my spring boot application?

We can use the Maven command in the terminal “./mvnw package“. It will be generated the .jar file in the target directory of the Spring project application.

Can I develop the Spring Boot applications using the another build tools like Gradle?

Yes, We can use the Gradle instead of the Maven, Just select the Generate the Gradle Project in the Spring Initializr step of the Spring project.

What is purpose of the @SpringBootApplication annotation?

This annotation is the convenience annotation that can adds all of the following @Configuration, @EnableAutoConfiguration and @ComponentScan of the spring project.

How do I run the Spring Boot application on the different port?

We can modify the application.properties file and add the server.port=8081 to change the port to 8081 of the Spring project.



Contact Us