Author
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.
@SpringBootApplication.Tips:
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
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
/actuator/loggers.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
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:
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.Spring Boot offers powerful debugging tools:
Using these methods together allows developers to identify issues quickly, inspect variables, and ensure smooth application behavior across development, testing, and production environments.