如何在 STS 中调试 Spring 引导 Web 应用程序?

How to debug a Spring Boot Web Application in STS?

我是 Spring 框架的新手,所以我从 Spring 启动项目开始。

特别是我拿了 https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-secure-jdbc project and modified the pom.xml so that it becomes self contained (replaced spring-boot-samples with spring-boot-starter-parent in the parent->artifactId tag, removed properties node, added in repositories and pluginRepositories from http://docs.spring.io/spring-boot/docs/1.2.2.BUILD-SNAPSHOT/reference/htmlsingle/#getting-started-maven-installation).

我首先使用 'mvn spring-boot:run' 在 STS 之外成功构建并 运行 这个应用程序,然后将 Maven 项目导入到 STS 中,它成功构建并运行。

我可以通过右键单击项目文件夹并选择 运行->Debug As ...->Spring Boot App 来调试此应用程序,并且调试器会在断点处停止我在 ApplicationSecurity class 方法中进行了设置。但是,浏览器 window 不会在 STS 或系统浏览器中自动弹出(我预计 - 这是正确的吗?)。

当我使用 STS/Eclipse 中的 'Internal Web Browser' 浏览到本地主机(端口 8080)时,HTML 页面呈现出来,但我在 @RequestMapping(" /") 方法没有被命中(我怀疑这可能是因为浏览器与调试器处于不同的进程中)。

那么,如何在 STS 中调试 @RequestMapping 方法 - 这将帮助我更好地理解 Spring 框架。

我对Eclipse/STS的了解有限,我的安装会不会有问题?

您不需要使用嵌入式浏览器来调试服务器(浏览器是一个单独的进程)。如果您的 @RequestMapping 断点没有命中,那么我怀疑 Spring 出于某种原因(也许是安全性?)没有发送到这些路由。