How to debug a Spring Boot application in Spring Tool Suite

落爺英雄遲暮 提交于 2021-02-19 04:35:08

问题


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:

  1. Select Window-->Show View--> Servers.
  2. Right Click on server in the Servers panel, select "Debug".
  3. Add breakpoints in your code
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!