简体   繁体   English

IntelliJ 不会终止 Spring 使用 gradle 构建的引导应用程序

[英]IntelliJ does not terminate Spring Boot applications build with gradle

I am using IntelliJ 13.1 on Linux and try to build a basic REST application following the example http://spring.io/guides/gs/spring-boot/我在 Linux 上使用 IntelliJ 13.1 并尝试按照示例http://spring.io/guides/gs/spring-boot/构建一个基本的 REST 应用程序

When I execute the target bootRun from within IntelliJ the intergrated tomcat server is started and everything works fine.当我从 IntelliJ 中执行目标 bootRun 时,集成的 tomcat 服务器启动并且一切正常。

10:09:35: Executing external task 'bootRun'...
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:bootRun

But stopping the execution does not affect the gradle task:但是停止执行不影响 gradle 任务:

10:11:40: External task execution finished 'bootRun'.

I still can access the tomcat instance on the configured port.我仍然可以在配置的端口上访问 tomcat 实例。 Only closing IntelliJ will destroy the process.只有关闭 IntelliJ 才会破坏进程。

I searched on this topic but could not find any reasonable answers.我搜索了这个主题,但找不到任何合理的答案。 I wonder if it is a我想知道这是不是一个

  • gradle problem (using gradle wrapper version 1.11) gradle 问题(使用 gradle 包装器版本 1.11)
  • Linux problem (Ubuntu 12.04) Linux 问题(Ubuntu 12.04)
  • IntelliJ problem (IDEA 13.1.2) IntelliJ 问题(IDEA 13.1.2)
  • Spring Boot problem (tried different versions from 1.0.0.RELEASE to 1.1.0.M2) Spring 引导问题(尝试了从 1.0.0.RELEASE 到 1.1.0.M2 的不同版本)

I am pretty sure it's an IntelliJ issue because: 我很确定这是一个IntelliJ问题,因为:

When you run the bootRun from IntelliJ's Gradle integration and then press stop, the application continues to run as you mentioned. 当您从IntelliJ的Gradle集成运行bootRun然后按stop时,应用程序将继续运行,如您所述。

However, if you use the command line and run gradle bootRun and then use Cntrl + C , the application stops just fine. 但是,如果您使用命令行并运行gradle bootRun然后使用Cntrl + C ,应用程序就会停止正常。

Note that my setup is Windows 7, IntelliJ 13.1.3, Gradle 1.12 and Spring Boot 1.1.0.M2. 请注意,我的设置是Windows 7,IntelliJ 13.1.3,Gradle 1.12和Spring Boot 1.1.0.M2。

If your need to is to be able to easily debug your application, all you need to do is run the Java (or Groovy) Class that has the main method, since that it is the easiest way to run Spring Boot applications! 如果您需要能够轻松调试应用程序,那么您需要做的就是运行具有main方法的Java(或Groovy)类,因为它是运行Spring Boot应用程序的最简单方法! Kudos to Spring Boot for that!!! 感谢Spring Boot!

Of course you can continue to use Gradle for tasks like running all the tests or creating the packaged application. 当然,您可以继续使用Gradle执行运行所有测试或创建打包应用程序等任务。

It's may not perfect solution.这可能不是完美的解决方案。 But for a quick fix, it will help you.但为了快速修复,它会帮助你。

Goto terminal and apply this command to terminate the process转到终端并应用此命令终止进程

  sudo kill -9 `sudo lsof -t -i:8080`

Note: Replace your port number instead of 8080注意:替换你的端口号而不是 8080

I know this answer was already answered, but as this is first topic when searching in Google, I thought in sharing an alternative I went with and didn't find in other topics I read. 我知道这个答案已经得到了解答,但由于这是在谷歌搜索时的第一个主题,我想在分享一个替代方案,我去了,并没有找到我读过的其他主题。

My main problem with this terminate was that always I changed something in my classes, I needed to restart the server, and it would fail so I needed to stop/start the server sometimes. 这个terminate主要问题是我总是在我的类中改变了一些东西,我需要重新启动服务器,它会失败所以我需要有时stop/start服务器。

To avoid this, I use spring-boot-devtools . 为避免这种情况,我使用spring-boot-devtools Basically: 基本上:

Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. 使用spring-boot-devtools的应用程序将在类路径上的文件发生更改时自动重新启动。

The only catch is that on Intellij it only makes the project if click Build > Make Project , so either set it to build automatically or remember to click on make . 唯一美中不足的是,上的IntelliJ它只是makes该项目,如果点击Build > Make Project ,所以将它设置为自动构建或记住点击make

To use, simply add the dependency to your build.gradle / pom.xml : compile('org.springframework.boot:spring-boot-devtools') 要使用,只需将依赖项添加到build.gradle / pom.xmlcompile('org.springframework.boot:spring-boot-devtools')

I found this to be really useful in development. 我发现这在开发中非常有用。

I am using IntelliJ in Mac, running Spring boot application was giving the same issue. 我在Mac上使用IntelliJ,运行Spring启动应用程序也给出了同样的问题。 Whenever I run the app in Terminal and use CTRL + Z, the terminal will strop running the app. 每当我在终端中运行应用程序并使用CTRL + Z时,终端将运行应用程序。 But when I run the app again in the same terminal, will give error saying the port 8080 was in use. 但是当我在同一个终端再次运行应用程序时,会给出错误,说端口8080正在使用中。 I just tried the option to close the Terminal session ( right click -> select -> Close Session). 我刚试过关闭终端会话的选项(右键单击 - >选择 - >关闭会话)。 This will close the terminal, and when I clicked the terminal option again and ran the app, it ran smoothly. 这将关闭终端,当我再次单击终端选项并运行应用程序时,它运行顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM