How to debug spring-boot application with IntelliJ IDEA community Edition?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Debugging is essential for any application development, allowing developers to analyze the code and find the root causes of bugs effectively. This article guides you on how to debug a Spring Boot application using IntelliJ IDEA Community Edition. Even though the Community Edition lacks some advanced features of the Ultimate Edition, it offers powerful tools for debugging.
Setting Up Your Environment
Before diving into debugging, you must have the following software installed on your system:
- Java Development Kit (JDK): Ensure you have JDK installed and configured properly, as Spring Boot projects are Java-based.
- Spring Boot: Confirm that you have a Spring Boot application set up. If not, create a simple one using Spring Initializr.
- IntelliJ IDEA Community Edition: Download and install the latest version from the JetBrains website.
Creating a Spring Boot Application
To get started, you can create a basic Spring Boot application using Spring Initializr. Follow these steps:
- Navigate to Spring Initializr:
- Choose the project type as "Maven Project".
- Select the language as "Java".
- Choose a Spring Boot version (e.g.,
2.7.0). - Add dependencies as required, such as "Spring Web" for a web application.
- Generate the Project:
- Click the "Generate" button to download the project zip file.
- Extract the project to a suitable directory on your system.
- Open the Project in IntelliJ IDEA Community Edition:
- Launch IntelliJ IDEA and open your project by selecting
File > Openand navigating to your project directory.
Configuring the Application for Debugging
With the project open in IntelliJ IDEA, you need to set up your application to enable debugging:
- Edit Configurations:
- Go to the "Run" menu and select "Edit Configurations".
- Add a New Configuration:
- Click on the
+ (Add New Configuration)button and choose "Application". - Set a meaningful name for your configuration.
- In the "Main class" field, specify the class that contains your
mainmethod.
- Set VM Options for Debugging:
- In the "VM options" field, you can specify options like
-Xmx1024mto allocate memory. More importantly, if you are remotely debugging, you can specify options such as-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005to enable remote debugging via a specified port.
Using Breakpoints and Debugging
Breakpoints are crucial in debugging, allowing the program execution to pause at specified points. Here’s how you can use breakpoints effectively:
- Set Breakpoints:
- Open the Java class file in which you wish to set breakpoints. Click on the left-hand gutter adjacent to the line numbers to set a breakpoint. You'll see a red dot indicating the breakpoint.
- Start Debugging:
- Select your configuration and click the debug button (a green bug icon) in the top-right corner of the IDE. This launches your application in debug mode.
- Navigate Through Breakpoints:
- As the application hits breakpoints, use the debugging panel to use options such as:
- Step Over (F8): Move to the next line without stepping into method calls.
- Step Into (F7): Go inside the method calls.
- Step Out (Shift + F8): Exit the current method being debugged.
- Resume (F9): Continue execution until the next breakpoint or the program’s end.
- Inspect Variables:
- While paused at a breakpoint, you can hover over variables to view their current state. Alternatively, open the "Variables" panel to see all currently accessible variables and their values.
- Evaluate Expressions:
- Use the "Evaluate Expression" window (Alt + F8) to test expressions or code snippets, offering a quick way to test changes without restarting the application.
Additional Tips
- Conditional Breakpoints: You can make a breakpoint conditional, activating it only when specific conditions are met. Right-click the breakpoint, select "More", check "Condition", and enter your condition.
- Exception Breakpoints: Use the "Add new exception breakpoint" option to pause execution whenever a specified exception is thrown.
- Hot Swap: IntelliJ IDEA supports the Hot Swap feature, letting you update the code in the running JVM without restarting the application.
- Logging: Before debugging, check your application logs for context, which can offer insights and narrow down the code area to inspect.
Summary Table
| Feature/Step | Description |
| Breakpoints | Pause the execution at certain points to inspect variables |
| Step Over (F8) | Skip over method calls to the next statement |
| Step Into (F7) | Enter into the method call for deeper inspection |
| Step Out (Shift + F8) | Exit the current method and return to the caller |
| Evaluate Expression (Alt + F8) | Test code snippets in real-time |
| Conditional Breakpoints | Activate breakpoints based on conditions |
| Hot Swap | Update code in the running JVM without restart |
Conclusion
Debugging in IntelliJ IDEA Community Edition provides powerful tools to understand and resolve issues within your Spring Boot applications. By effectively using features like breakpoints, step navigation, and expression evaluation, you can streamline the debugging process and significantly increase productivity. While the Community Edition may lack some advanced features found in the Ultimate Edition, its robust capabilities still make it an excellent choice for Java development.
Related reading
- How to debug Spring Boot application with Eclipse?
- How to decide the concurrency to be set in spring kafka?
- How to declare an ArrayList with values?
- How to declare another Jackson ObjectMapper without affecting 'clients' of the original bean?
- How to debug Tensorflow segmentation fault in model.fit?
- How to debug timeout failures made in Play?
- How to declare or mark a Java method as deprecated?
- How to decompile a whole Jar file?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.