如何在Spring Tool Suite中调试Spring Boot应用程序 [英] How to debug a Spring Boot application in Spring Tool Suite

查看:265
本文介绍了如何在Spring Tool Suite中调试Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Spring Tool Suite中调试一个简单的Spring Boot应用程序.这是一个简单的宁静的Web服务.我想用嵌入式tomcat服务器调试控制器和服务类.

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.

找到了此帖子如何调试SpringSpring Source Tool Suite上的MVC应用程序.我遵循了以下步骤:

Found this post how to debug Spring MVC application on Spring Source Tool Suite. I followed the steps:

  1. 选择窗口->显示视图->服务器.
  2. 右键单击服务器"面板中的服务器,选择"调试".
  3. 在代码中添加断点
  4. 然后右键单击应用程序,选择调试为->在服务器上调试

经过前2个步骤后,控制台中的输出显示服务器已启动.但是,右键单击控制器类时,可以找到在服务器上调试的选项. Application 类是我可以调试的唯一类.但是,没有办法从 Application 中进入" Controller .

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?

推荐答案

首先让我们看看如何在调试模式下启动Spring Boot应用.

First of all let's see how to launch you Spring Boot app in debug mode.

使用Spring Boot时,不需要应用服务器即可运行或调试它,因为它可以通过启动 Application 类以独立模式运行.

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:

  • 右键单击您的 Application 类,然后选择调试为-> Spring Boot应用.调试为-> Java应用程序也将起作用.
  • 打开 Boot Dashboard 视图,右键单击您的应用程序,然后选择(重新)调试).
  • 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

一旦应用程序以调试模式运行或之前运行,就没关系了,请打开要调试的类(在您的情况下为 Controller ),然后转到感兴趣的行要在该行添加断点,请在该行的编辑器左端的灰色栏中右键单击,然后选择切换断点*",或仅使用 Shift + Ctrl + B .

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.

这篇关于如何在Spring Tool Suite中调试Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆