I have a rest api springboot application which is in trouble but I am not very much familiar with this language.
I use IntelliJ IDEA CE (Community Edition) for all my dev projects, so I would like to keep using this IDE.
My problem is that I don't know how to debug a springboot application and also don't know how to do it using IntelliJ. I have alreay tried some tutorials in the internet bu withou success.
I remember that in Grails I learned to do it here at Stackoverflow, and I had to add a Remote JVM debugger and use the command gradle debug-jvm. So I could stop the application at the breakpoint and debug it to find my bugs.
Could anyone help me?
Thanks.
Alfredo
CodePudding user response:
I guess you have at least a main method inside SpringBootApplication annotated class, something like this :
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Add a debug breakpoint in front on the line containing 'SpringApplication.run' (the red dot on the picture below) and start your application in debug by right-clicking on the 'main' method and choose Debug 'Application.main()' :
Now the application should starts in debug mode and the execution flow should have stopped on the line with the debug breakpoint (blue highlighted below) :
Next time you want to start the application in debug mode you can directly click on the 'debug' bouton (the green 'bug' button on top-rigth corner of the picture above)
You can see the current state of your application inside the debugger view at the bottom of your IDE :
Now your are familiar with debuging you can add debug breakpoints wherever you want, inside your Rest controller methods for example.
You can find the complete documentation about debugging on JetBrains web site : Debug code This part should especially interests you : Tutorial: Debug your first Java application