1

When I start the app with mvn spring-boot:run, my breakpoints don’t hit. I’m trying to debug a simple REST endpoint annotated with @GetMapping.

Minimal Reproducible Example:

@RestController
@RequestMapping("/api")
public class HelloController {
 @GetMapping("/hello")
 public String hello() {
 // <-- breakpoint here
 return "hi";
 }
}

Expected Behavior

The breakpoint should hit when calling GET http://localhost:8080/api/hello.

What I tried

  • Running from IntelliJ with the app’s Run button (works sometimes, but not with the Maven goal).
  • Adding -Dspring-boot.run.fork=false to the goal.
  • Using "Attach to Process", but I don’t see a JDWP port.
asked Oct 11 at 13:13
2
  • Why not executing the Spring Boot App class from your IDE instead of calling mvn spring-boot:run ? If you like to get a break-point working you need to attach your IDE to the executed JVM ... Commented Oct 11 at 20:22
  • You could do that if you need to via mvn spring-boot:run -Dspring-boot.run.jvmArguments=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 ... But I recommend to debug your application within your IDE... docs.spring.io/spring-boot/maven-plugin/… Commented Oct 12 at 11:58

2 Answers 2

3

mvn spring-boot:run runs a Spring application just like you could run any other application from the console. This does not start Java with a debugger.

The easiest and most convenient way to debug a Spring application is typically to just run the main class from your IDE. That way, you can just debug it as you would with any other application.

If you want to keep using mvn spring-boot:run, you can add JVM arguments for debugging which you can do using spring-boot.run.jvmArguments.

Finally, if you are running the application directly within Maven without forking, you cannot add JVM arguments at runtime. Instead, you'd have to debug the Maven process. You can do so by running mvnDebug instead of mvn (so mvnDebug spring-boot:run) in Maven 3.x or using mvn --debug spring-boot:run with Maven 4. This essentially adds the JVM arguments necessary for debugging when running Maven.

Note that for the last two options (using JVM args), you have to attach the debugger after starting the application. If you are using suspend=y, Java will wait for you to attach a debugger before actually starting the application.

answered Oct 11 at 23:28
Sign up to request clarification or add additional context in comments.

2 Comments

Using mvnDebug will start debugger for Maven itself and not for your appllication... does not make sense...
If you are running an application without forking (if this option is available and works), it runs in the same JVM as Maven hence debugging Maven also debugs the application. The same also applies to mvn exec:java (but not mvn exec:exec).
0

This issue occurs because when you run your Spring Boot application using mvn spring-boot:run from IntelliJ IDEA's terminal (or an external terminal), the app runs outside of the IDE's debugging context. That means IntelliJ can’t attach breakpoints unless you explicitly run the app in debug mode and attach the debugger.

Fix : Use IntelliJ’s built-in Spring Boot support

The simplest and most reliable fix is to run your Spring Boot app directly from IntelliJ, like this:

  1. Open your main application class (annotated with @SpringBootApplication).

  2. Click the green Run/Debug button next to the main() method.

  3. Or use the pre-configured Spring Boot run/debug configuration in the Run Configurations menu.

  4. Set breakpoints as needed — they will be hit correctly.

This way, the app runs inside IntelliJ’s JVM with full debugging support.

answered Oct 14 at 3:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.