Thanks to the suggestion from https://stackoverflow.com/a/47064387/509565 I've worked out the solution:
- Use
spring-boot:run -Dspring-boot.run.fork=falseas your laucher command line - Ensure that "Delegate IDE build/run actions to Maven" in "Build ...> Build Tools > Maven > Runner" settings is NOT checked
Edit:
It seems that this trick isn't working anymore (Intellij-Idea 2024.4.4, Java 17): you can always start the application from the @SpringBootApplication itself.
spring boot - Cannot debug / stop a springboot app with IntelliJ Idea community - Stack Overflow
java - How to debug spring-boot application with IntelliJ IDEA community Edition? - Stack Overflow
IntelliJ debugger no longer stops at breakpoints
java - Spring Boot application doesn't stop at any breakpoint in debug - Stack Overflow
Videos
EDIT: it does not work anymore from Spring Boot 3+. See Ruik's comment
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
Using IntelliJ Community Edition 2022.3.2 for Windows, I was debugging just fine until I decided to run some unit tests manually by going to the file in the proyect explorer, double clicking it and selecting "run". As a result, the debugger (Remote JVM Debug) no longer stops at breakpoints.
My best guess is that running the unit test created another JVM or Java Project and the debugger attachs to it whenever I run it but I tried restarting my PC to kill all processes and didยดt work. Also tried uninstalling Tomcat and IntelliJ because I notice that before running the unit test, it built the proyect and thatยดs something I never do using the IntelliJ Build Project tool, I always do it via CMD
I created a post in StackOverflow but got no answer. Pelase feel free to check the post asi i added a lot more information there.
Any kind of information or workaround I can try is welcome, i have been struggling with this issue for 2 days now.