Debugging Spring Boot Applications in Visual Studio Code | Generated by AI

Home PDF

To debug a Maven Spring Boot project in Visual Studio Code (VSCode), you can follow these straightforward steps to set up and run your application in debug mode. This guide assumes you have a basic Maven Spring Boot project with a pom.xml file and a main class annotated with @SpringBootApplication. Here’s how to do it:

Step 1: Install Necessary Extensions

Before you begin, ensure that VSCode is equipped with the required extensions for Java and Spring Boot development:

To install these:

  1. Open VSCode.
  2. Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS).
  3. Search for “Java Extension Pack” and “Spring Boot Extension Pack,” then click Install for each.

Step 2: Open Your Maven Spring Boot Project

Step 3: Create or Edit the launch.json File

To configure debugging, you need to set up a launch.json file in VSCode:

  1. Open the Run and Debug view by clicking the bug-and-play icon in the sidebar or pressing Ctrl+Shift+D.
  2. If no debug configuration exists, click “create a launch.json file”. If one already exists, click the gear icon to edit it.
  3. When prompted, select Java as the environment. VSCode will generate a default launch.json file in a .vscode folder within your project.
  4. Add or modify a debug configuration for your Spring Boot application. Here’s an example configuration:

     {
         "type": "java",
         "name": "Debug Spring Boot",
         "request": "launch",
         "mainClass": "com.example.demo.DemoApplication",
         "projectName": "demo"
     }
    
    • Replace "com.example.demo.DemoApplication" with the fully qualified name of your main class (e.g., com.yourcompany.yourapp.YourApplication).
    • Replace "demo" with your project’s name, typically the <artifactId> from your pom.xml.
  5. Save the launch.json file.

Optional: Add Arguments

If your application requires specific arguments (e.g., Spring profiles), you can include them:

{
    "type": "java",
    "name": "Debug Spring Boot",
    "request": "launch",
    "mainClass": "com.example.demo.DemoApplication",
    "projectName": "demo",
    "args": "--spring.profiles.active=dev"
}

Step 4: Start Debugging

Step 5: Set Breakpoints and Debug

Alternative Methods

While the launch.json method is recommended for its flexibility, you can also debug using:

Prerequisites and Notes

By following these steps, you can effectively debug your Maven Spring Boot project in VSCode, leveraging its powerful debugging tools to identify and resolve issues in your code.


Back 2025.03.13 Donate