How to debug Spring rest controller from IDEA?

Answered

How do I bebug Spring Http Controllers in IDEA.  
I mean - Im talking about debugging code that's initiated by GET request?   
I've tried:

a) clicking on `run` and then issuing GET request in the browser -> but code didn't stop on breakpoints.

b) just clicking on debug -> but since that code never get's called without http request -> nothing happens.


What am I missing?

 

P.S.

Ive got debugging to work by adding "remote debugging" configuration in intellij and then launching jar with: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Then I've issued get request in a browser -> and can debug in intellij.
But it still seems like too much work.. there is gotta be a simpler way.

 

0
3 comments

Do you want IntelliJ IDEA to automatically issue a GET request after debug session is started? Is that a web project deployed on a server or is it a spring boot app with embedded web server?

0
Avatar
Permanently deleted user

It's a spring boot app with tomcat embedded.

 

>to automatically issue a GET request after debug session is started

If that's how it works then yes.

0

You can use Spring Boot debug configuration: https://www.jetbrains.com/help/idea/run-debug-configuration-spring-boot.html.

To automate opening the URL to call the controller you can use Ant, Maven or Gradle custom task that will either start the browser at the specified URL or will use some command line tool for that (like wget or curl). IntelliJ IDEA allows to configure Ant, Maven or Gradle tasks to be executed automatically after certain Run/Debug configuration is called, or you could make an external tool for wget and bind it to some keyboard shortcut.

0

Please sign in to leave a comment.