Thanks to the suggestion from https://stackoverflow.com/a/47064387/509565 I've worked out the solution:

  1. Use spring-boot:run -Dspring-boot.run.fork=false as your laucher command line
  2. 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.

Answer from lrkwz on Stack Overflow
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 6796164198546-Intellij-not-stopping-at-breakpoints
Intellij not stopping at breakpoints – IDEs Support (IntelliJ Platform) | JetBrains
If you really need to use Maven goal for debugging you need to add debug arguments to the process which runs the boot run maven goal, see https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/maven-plugin/examples/run-debug.html And then connect ...
Discussions

java - How to debug spring-boot application with IntelliJ IDEA community Edition? - Stack Overflow
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 More on stackoverflow.com
🌐 stackoverflow.com
IntelliJ debugger no longer stops at breakpoints
Just a stab in the dark, but did you re-select and run your remote debug run configuration? IntelliJ retains the last run config, regardless of how it was executed. If not, you need to provide a lot more detail. That SO post is likely to get removed for lack of detail and being possibly off-topic (IDE-specific). More on reddit.com
🌐 r/IntelliJIDEA
5
6
February 8, 2023
java - Spring Boot application doesn't stop at any breakpoint in debug - Stack Overflow
What I should do to make my IDEA stop at breakpoint in debug? I suppose that issue is about forking JVM but can't resolve it. ... No, because it's not Maven application in that tutorial. ... Looks like IntelliJ is not connected to the running application. More on stackoverflow.com
🌐 stackoverflow.com
Debugger stopping on breakpoint only at first and every 10th try
How much time between request 1 and 10? GET responses can be cached, maybe test again with a POST or PUT method. More on reddit.com
🌐 r/learnjava
11
5
May 5, 2022
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 12637593520402-Breakpoints-not-working-in-spring-boot-app
Breakpoints not working in spring boot app – IDEs Support (IntelliJ Platform) | JetBrains
You could try the suggestion here ...us=Comments-27-4758555.0-0 Or open the main class annotated with `@SpringBootApplication`, and click the run icon in the IDE's left gutter to debug it directly....
Top answer
1 of 13
213

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.

2 of 13
109

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

🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360009993679-Spring-boot-app-doesn-t-stop-on-breakpoints-and-doesn-t-kill-process-after-stopping
Spring boot app - doesn't stop on breakpoints and doesn't kill process after stopping – IDEs Support (IntelliJ Platform) | JetBrains
So today, my spring boot app doesn't stop on breakpoints, and when I need to re-run it with gradle's bootRun task, previously running instance is not stopped automatically - and because they use some shared recourse, I have to kill it manually. ... Hello. Does it help if you remove .idea folder and reimport the project? ... Hi In fact, yes and no. I checked out repo from scratch, changed run/build "with intellij" instead of "with gradle" and also in debug configuration -> added "debug all tasks" in "gradle debug" tab.
🌐
Coderanch
coderanch.com › t › 769783 › intellij-idea › ide › spring-boot-run-hit-break
spring-boot:run cannot hit break point (IntelliJ IDEA forum at Coderanch)
in run configuration, I choose Maven and set run command as spring-boot:run, then I set break point in code and run the configuration, but I find intellij cannot hit the break point. but if I create another run configuration, choose Application and set the main class, then when run this configuration, Intellij can hit the break point. 1) why if using spring-boot:run to run, Intellij cannot hit the break point? 2) how to make Intellij can also hit the break point even using spring-boot:run to run? ... IntelliJ works by connecting to the debugger that is built into the JVM.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360001580439-Not-able-to-hit-a-breakpoint-in-IntelliJ-when-trying-to-remote-debug-a-executing-test
Not able to hit a breakpoint in IntelliJ when trying to remote debug a executing test – IDEs Support (IntelliJ Platform) | JetBrains
November 16, 2018 - I have created a remote debug configuration in IntelliJ with port as 5005 · I am running this command: gradle test -Dtest.debug on command line · I see build output that the build is waiting for the debugger to connect to port 5005 and the process suspends · At this point I run my remote debug configuration and it successfully connects to port 5005 · After this the JUnit test is executed but the debugger does not stop at the breakpoints.
Find elsewhere
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 10000635378450-IntelliJ-debugger-no-longer-stops-at-breakpoints
IntelliJ debugger no longer stops at breakpoints – IDEs Support (IntelliJ Platform) | JetBrains
February 8, 2023 - Use TcpView to ensure it's a correct Tomcat instance listening for debugger on port 8000. Make a change in your code like adding a logging statement, put a breakpoint on this line, build/deploy the new app, restart Tomcat.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360009815040-Intellij-debugger-does-not-stop-at-breakpoint-until-the-debugger-is-restarted
Intellij debugger does not stop at breakpoint until the debugger is restarted – IDEs Support (IntelliJ Platform) | JetBrains
October 10, 2020 - I am using Intellij Idea Ultimate on macOS. I am trying to debug a remote Spring boot application. The debugger sometimes doesn't stop at the breakpoint. I have to restart the debugger to make it s...
🌐
Reddit
reddit.com › r/intellijidea › intellij debugger no longer stops at breakpoints
r/IntelliJIDEA on Reddit: IntelliJ debugger no longer stops at breakpoints
February 8, 2023 -

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.

🌐
DEV Community
dev.to › davey › debugging-springboot-application-in-intellij-idea-ce-22j9
Debugging SpringBoot Application In IntelliJ Idea CE - DEV Community
October 12, 2022 - When debugging a SpringBoot application in IntelliJ Idea Community Edition, additional steps need to be taken. If you have defined your run configuration as spring-boot:run, you will find that the application runs, but does not stop at breakpoints as expected.
🌐
Stack Overflow
stackoverflow.com › questions › 63814541 › spring-boot-application-doesnt-stop-at-any-breakpoint-in-debug
java - Spring Boot application doesn't stop at any breakpoint in debug - Stack Overflow
MAVEN_DEBUG_OPTS in ${MAVEN_HOME}\bin\mvnDebug.cmd: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -DforkMode=never -Dmaven.failsafe.debug · So I started the app, see a prompt: Listening for transport dt_socket at address: 5005 · Then I ran 'remote' run configuration. I can see how my app has started. Then I invoked controller's endpoint. I can see stop string in the log. Then I put a breakpoint at string System.out.println("stop");. Invoked again controller's method. And I can see again stop string in the log instead of stopping at breakpoint.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-188058 › cant-debug-spring-boot-project-by-spring-bootrun
can't debug spring boot project by "spring-boot:run"
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-252635
Debug did not stop on breakpoint for Spring Boot Application ...
November 19, 2020 - {{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360007199739-unable-to-debug-spring-boot-application-with-postman-requests
unable to debug spring boot application with postman requests – IDEs Support (IntelliJ Platform) | JetBrains
I have the same issue with IDEA community version with spring boot application. Postman send the request and the app is processing successully (see the logs) and see the response back in postman but IDEA doesn't stop in the breakpoint. breakpoint is not disabled. ... If you are using Maven configuration, IDE debugger connects to the Maven JVM and breakpoints will not work as your code runs in the different JVM forked by Maven. Consider using IntelliJ IDEA Ultimate with the Spring Boot debug configuration or use Application debug configuration instead of Maven.
🌐
Reddit
reddit.com › r/learnjava › debugger stopping on breakpoint only at first and every 10th try
r/learnjava on Reddit: Debugger stopping on breakpoint only at first and every 10th try
May 5, 2022 -

SOLVED: Apparently I've been wrongly assuming 'running to cursor' did the same as resuming when there are no more breakpoints. Using F9 to resume worked just fine.

This is by far the weirdest problem I've had in a while.

It's a simple spring boot project. Tried with Gradle and Maven, tried calling the service with Insomnia and Mozilla. Tried disabling firewall, tried with IntelliJ community And IntelliJ ultimate, the result is always thr same:

When calling GET service, the breakpoint always hits at first as it should. Then I push the 'run to cursor' button and call the GET service once again. For 9 times the breakpoint doesn't get hit and I'm receiving the response. When I call the same service for the 10th time the breakpoint gets hit. And so on (gets hit on every 10nth try)

What on earth could cause this?

Top answer
1 of 2
2
How much time between request 1 and 10? GET responses can be cached, maybe test again with a POST or PUT method.
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 9250565005586-Maven-Run-configuration-spring-boot-unable-to-debug
Maven Run configuration spring boot unable to debug. – IDEs Support (IntelliJ Platform) | JetBrains
Running the app works just fine, but if I try to start it in debug mode, it never hits any of my breakpoints. The same app running with a Spring Boot run configuration starts in debug mode just fine. However, Spring Boot run does not generate a build.properties file like mvn spring-boot:run does which my app needs to be able to run correctly. I found this: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007199739/comments/360002405220 Is there any way to get spring run config to both generate the BuildProperties bean that my app needs while also using the SpringBoot run configuration?
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-296707 › Debugging-tests-from-IntelliJ-202132-does-not-stop-at-breakpoints
Debugging tests from IntelliJ 2021.3.2 does not stop at ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 10872
Does not stop at breakpoints when using 2.0.0.M5 in IntelliJ with gradle bootRun · Issue #10872 · spring-projects/spring-boot
November 1, 2017 - Execution doesn't stop at breakpoints for 2.0.0.M5 applications when running gradle bootRun task in IntelliJ. It works fine with 1.5.8.RELEASE. Also, execution stops when running 2.0.0.M5 appli...
Author   koju