Recently, it was found that the local debugging of Spring Boot cannot be done. After the original Spring Boot upgrade, the command parameters of the corresponding plug-in have changed. Therefore, this article will perform an upgrade.

Background:

When you run the spring-boot:run command using the Spring Boot Maven plug-in, if the breakpoint cannot be entered, perform the following operations:

Official solution:

By default, the run goal runs your application in a forked process. If you need to debug it, you should add the necessary JVM arguments to enable remote debugging. The following configuration suspend the process until a debugger has joined on port 5005:

Let’s just do it!

1. Add JVM parameters

Add jvmArguments to the spring-boot-Maven-plugin.

<project> ... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version> 2.0.release </version> <configuration> < jvmargp > -xdebug -xrunjDWp :transport=dt_socket,server=y,suspend=y,address=5005
          </jvmArguments>
        </configuration>
        ...
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>
Copy the code

Or specify on the command line:

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Copy the code

For the latest configuration, please refer to the official instructions:

Docs. Spring. IO/spring – the boot…

2. Add a Remote

Add a Remote configuration to the developer tool:

You only need to set the Host and Port parameters.

  • Address of the Host:

Localhost: indicates the local boot address.

  • Port: the Port

5005: the port specified by the command line above;

3. Start debugging

Start the Spring Boot project with the jvmArguments parameter:

The program stops on the listening port: 5005, and then debug starts Remote:

Go back to the project, start logging, and then you can debug breakpoints.

This is remote debugging, also can help you debug remote Spring Boot application, but local debugging requires two operations, slightly troublesome.

In the end, the stack manager will share the latest technology tutorial of Spring Boot. Now he has written a pile of inventory, follow the wechat public account “Java Technology stack “, the public account will be pushed as soon as possible!