问题
I'd like to debug a simple Spring Boot application in Spring Tool Suite. It is a simple restful web service. I wanted to debug the controller and service class with embedded tomcat server.
Found this post how to debug Spring MVC application on Spring Source Tool Suite. I followed the steps:
- Select Window-->Show View--> Servers.
- Right Click on server in the Servers panel, select "Debug".
- Add breakpoints in your code
- Then right click on application, Select Debug As --> Debug on Server
After the first 2 steps, the output in console shows server has started up. However, I could find option of Debug on Server when I right clicked controller class. Application class is the only class that I could debug. However there is no way to "step into" Controller from Application.
Also, when should I launch browser and put in the request url?
回答1:
First of all let's see how to launch you Spring Boot app in debug mode.
As you are using Spring Boot, you don't need an app server to run or debug it, as it is able to run in standalone mode by launching the Application class.
You have at least two ways to launch it in debug mode:
- Right click on your Application class and select Debug as -> Spring Boot App. Debug as -> Java application will also work.
- Open the Boot Dashboard view, right click on you application and select (Re)debug).
You can have more information about the Boot dashboard in this blog post: https://spring.io/blog/2015/10/08/the-spring-boot-dashboard-in-sts-part-1-local-boot-apps
Once the application is running in debug mode or before, it really doesn't matter, open the class (in your case the Controller) you want to debug and go to the line you are interested in. To add a breakpoint at that line, right click in the grey bar at the left end of the editor in that line and select **Toggle Breakpoint*, or just use Shift+Ctrl+B.
Then you can launch the browser and use the application. When the execution gets to the line where you have added the breakpoint, it will stop there.
来源:https://stackoverflow.com/questions/36583947/how-to-debug-a-spring-boot-application-in-spring-tool-suite