How to debug spring-boot application with IntelliJ IDEA community Edition?

I'm having difficulties in debugging a Java spring-boot application on IntelliJ IDEA community Edition. The main problem is, that the IDE won't stop on a breakpoint, even the program surely executes through it. How can I make the the IntelliJ IDEA to stop on the breakpoint?

As additional information, here is my run configurations:

Maven configuration with a command as: spring-boot:run. Before launch I build the project.


tldr: You can try tweaking the command line like this:

spring-boot:run -Dspring-boot.run.fork=false

Explanation:

When running the application in debug mode, the IntelliJ debugger attaches to the Java process that it starts itself (by appending the appropriate parameters, -agentlib:jdwp etc, to the Java command line).

Quite often, these Java processes might then fork a new instance, which is not getting the same parameters, and because it is in a separate process, is not connected to the debugger. This can be confusing.

The spring-boot:run Maven goal, in addition to forking a new JVM, creates even more confusion, because it sometimes does fork and sometimes doesn't, depending on the options it gets, among other things. Some of this can be found in the documentation, but it's not always obvious.

You should first check whether the Java process actually is being debugged at all. When you start the application from IntelliJ, you will see messages scrolling by in the Run / Debug tab. At the top, there's the command line that is being executed. It should contain the debugger parameters (-agentlib:jdwp etc) and it should be followed by a message saying "Connected to the target VM", which is the debugger confirming that it has contact.

Next, if you are unsure if the JVM has been forked, you can check the process list in your OS, for example under MacOS and *nix you can use ps aux | grep java. The Java processes typically have a giant parameter list, most of which is the class path. The actual application being run is at the very end of the command line. If the JVM was forked, you have the process running the Maven goal, and another one running the Spring application. Then your debugger will be connected to the process you are not interested in, and your breakpoints won't work.

To stop spring-boot:run from forking, you can use the fork parameter above.


The only approach that worked for me, is running or debugging application directly from Intellij Idea. Just open class which contains

 public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

And click right mouse button->Debug my application


For me these steps work:

  1. Select menu Run -> Edit Configurations...
  2. Create new Remote Configuration. By default you don't need to change settings:
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005. But if you want for example to suspend JVM before you connects, you can change suspend=y. Or you can chage port etc.
  3. Copy command line depending your JVM version and save configuration.
  4. In Terminal window run your app with (in Maven usage case and JVM 1.5 and higher) mvn clean spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
  5. Connect to your app by running your Remote Configuration created prviously on step 2. Now you can debug your app.