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=falseto the goal. - Using "Attach to Process", but I don’t see a JDWP port.
2 Answers 2
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.
2 Comments
mvnDebug will start debugger for Maven itself and not for your appllication... does not make sense...mvn exec:java (but not mvn exec:exec).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:
Open your main application class (annotated with
@SpringBootApplication).Click the green Run/Debug button next to the
main()method.Or use the pre-configured Spring Boot run/debug configuration in the Run Configurations menu.
Set breakpoints as needed — they will be hit correctly.
This way, the app runs inside IntelliJ’s JVM with full debugging support.
Comments
Explore related questions
See similar questions with these tags.
mvn spring-boot:run? If you like to get a break-point working you need to attach your IDE to the executed JVM ...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/…