Debugging a Spring Boot Application
Debugging is a key part of Spring Boot development. It helps developers identify, trace, and fix issues in the application quickly. Spring Boot provides multiple ways to debug, including IDE debugging, remote debugging, logging, DevTools (hot reload), and Actuator endpoints.
1. Debugging from IDE (IntelliJ, Eclipse, VS Code, STS)
- Open the main class annotated with
@SpringBootApplication. - Right-click → Debug instead of Run.
- The IDE starts the embedded server in debug mode.
- Set breakpoints to inspect variables, application flow, and Spring beans.
Tips:
- Use step-over, step-into, and step-out to navigate the code.
- Inspect bean initialization and dependencies in runtime.
- Best suited for development environment debugging.
2. Remote Debugging with JVM Options
Useful when debugging a running JAR outside the IDE or in a production-like environment.
Enable remote debugging:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar app.jar
- Opens port 5005 for IDE connection.
- Connect your IDE debugger to this port.
- Helps debug deployed applications without stopping them.
3. Logging Configurations for Debugging
Spring Boot uses Logback (default) or other logging frameworks. Configuring logging properly helps trace request flow, detect errors, and inspect bean initialization.
Example – application.properties:
logging.level.root=DEBUG
logging.level.com.example.myapp=TRACE
- Adjust log levels per package for detailed debugging.
- Use TRACE, DEBUG, INFO, WARN, or ERROR levels as needed.
- Dynamic log levels can also be changed at runtime via Actuator
/actuator/loggers.
4. Changing Server Port
Sometimes you may need to run multiple instances of your app locally. You can change the server port in:
application.properties:
server.port=8081
application.yml:
server:
port: 8081
- Helps prevent port conflicts during development.
- Useful when testing multiple profiles (dev/test/prod) on the same machine.
5. Debugging with Spring Boot DevTools (Hot Reload)
DevTools enhances development efficiency by enabling automatic reloads on code or resource changes.
Add dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
Features:
- Automatic server restart on code changes.
- Live reload for templates and static resources.
- Speeds up testing and debugging during development.
6. Debugging Using Spring Boot Actuator
Actuator provides runtime insights to debug applications:
/actuator/health→ Check application health status./actuator/loggers→ Inspect and dynamically change log levels./actuator/metrics→ View runtime metrics like memory, requests, and DB connections.
Conclusion
Spring Boot offers powerful debugging tools:
- IDE breakpoints for detailed inspection.
- Remote debugging for running applications.
- Configurable logging for tracing execution.
- DevTools for hot reload during development.
- Actuator endpoints for runtime monitoring.
Using these methods together allows developers to identify issues quickly, inspect variables, and ensure smooth application behavior across development, testing, and production environments.
