Spring Boot

springmvc

Articles
Videos

Templates
Spring Boot Security
Database Migration

How can we debug a Spring Boot application?

By default, our pom.xml file should contains:

<build>
        <plugins>
                <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
        </plugins>
</build>

We need to add:

<configuration>
        <jvmArguments>
                -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
        </jvmArguments>
</configuration>

to the above pom.xml file so that it looks like:

<build>
        <plugins>
                <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                                <jvmArguments>
                                        -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
                                </jvmArguments>
                        </configuration>
                </plugin>
        </plugins>
</build>

Look at what we have done so far, and take note of the address=5005 part.

In Eclipse, do the following:

  1. Click on "Run -> Debug Configuration"
  2. Right click on "Remote Java Application" and select "New"
  3. In the "Name" field, give it a sensible name. This name can be the name of your project.
  4. In the "Port" field, type 5005
  5. Click on the "Apply" button
  6. Click on the "Close" button
  7. Open up the class file that we want to debug, and set a breakpoint
  8. Run the "spring-boot:run" Maven target. Spring Boot will now wait for Eclipse Debugger to connect, and the Console tab in Eclipse will show: "Listening for transport dt_socket at address: 5005".
  9. Click on "Run -> Debug Configuration""
  10. Expand "Remote Java Application"
  11. Click on the profile that we just created above and click on the Debug button. Spring Boot will now continue with its start-up sequence.
  12. Fetch a URL that would cause our class to be executed. At this point, Eclipse should automatically switch to the Debug perspective and pause on the line that we previously set the breakpoint.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License