A simple Spring Boot REST API application with debugging support in VS Code dev containers.
- Docker
- Visual Studio Code with Dev Containers extension
- Open this folder in VS Code
- When prompted, click "Reopen in Container" (or use Command Palette:
Dev Containers: Reopen in Container) - Wait for the container to build and dependencies to install
mvn spring-boot:runPress Ctrl+Shift+P (or Cmd+Shift+P on Mac) and select Tasks: Run Task → spring-boot:run
The application will start on http://localhost:8888
Open your browser or use curl:
curl http://localhost:8888/Expected response: Hello World! Current server time is: [timestamp]
-
Open a Java file (e.g.,
src/main/java/com/example/helloworldapi/controller/HelloWorldController.java) -
Set a breakpoint:
- Click on the left margin (line number gutter) next to the line where you want to pause
- A red dot will appear indicating the breakpoint is set
- Example: Set a breakpoint on line 15 in
HelloWorldController.java(thereturn greeting;line)
-
Start debugging:
- Press
F5(or click Run → Start Debugging) - Select "Debug Spring Boot App" from the configuration dropdown if prompted
- Wait for the application to start (you'll see debug controls appear at the top)
- Press
-
Trigger the breakpoint:
- Open your browser or use curl to hit the endpoint:
curl http://localhost:8888/
- The debugger will pause at your breakpoint
- You can now:
- Inspect variables in the Variables panel
- Step through code using the debug toolbar (Step Over, Step Into, Step Out)
- View the call stack
- Evaluate expressions in the Debug Console
- Open your browser or use curl to hit the endpoint:
-
Continue execution:
- Press
F5or click the Continue button to resume
- Press
If you already have the app running and want to attach the debugger:
-
Start the app with debug enabled:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" -
Attach the debugger:
- Press
Ctrl+Shift+Dto open the Run and Debug view - Select "Attach to Remote Spring Boot" from the dropdown
- Press
F5or click the green play button
- Press
-
Set breakpoints and test as described above
The project includes pre-configured debug settings in .vscode/launch.json:
- Debug Spring Boot App: Launches the application in debug mode
- Attach to Remote Spring Boot: Attaches to an already running application on port 5005
.
├── src/
│ └── main/
│ ├── java/
│ │ └── com/example/helloworldapi/
│ │ ├── HelloWorldApiApplication.java # Main application class
│ │ └── controller/
│ │ └── HelloWorldController.java # REST controller
│ └── resources/
│ └── application.properties
├── pom.xml # Maven configuration
└── .devcontainer/ # Dev container configuration
8888: Spring Boot application5005: Java debug port (JDWP)
- Java 21
- Spring Boot 3.4.0
- Maven 3.9.6
This project includes a GitHub Actions workflow that automatically builds and tests the application on every push or pull request to main branches.
- Sets up JDK 21
- Builds the project with Maven
- Runs all tests
- Packages the application as a JAR
- Uploads the built artifact
The workflow configuration is in .github/workflows/maven-build.yml.
- Ensure you started the app using the debug configuration (F5), not just
mvn spring-boot:run - Check that the red dot appears solid (not hollow) when you set a breakpoint
- Verify the Java extension pack is installed and active
# Find and kill the process using port 8888
lsof -ti:8888 | xargs kill -9# Clean and rebuild
mvn clean install