Java IntelliJ 不会终止使用 gradle 构建的 Spring Boot 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24010282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ does not terminate Spring Boot applications build with gradle
提问by Christian Metzler
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. Only closing IntelliJ will destroy the process.
我仍然可以在配置的端口上访问 tomcat 实例。只有关闭 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)
- Linux problem (Ubuntu 12.04)
- IntelliJ problem (IDEA 13.1.2)
- Spring Boot problem (tried different versions from 1.0.0.RELEASE to 1.1.0.M2)
- gradle 问题(使用 gradle 包装器 1.11 版)
- Linux 问题 (Ubuntu 12.04)
- IntelliJ 问题(IDEA 13.1.2)
- Spring Boot 问题(尝试了从 1.0.0.RELEASE 到 1.1.0.M2 的不同版本)
采纳答案by geoand
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.
当您运行bootRun
来自 IntelliJ 的 Gradle 集成然后按停止时,应用程序将继续按照您提到的方式运行。
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! Kudos to Spring Boot for that!!!
如果您需要能够轻松调试您的应用程序,您需要做的就是运行具有该main
方法的 Java(或 Groovy)类,因为这是运行 Spring Boot 应用程序的最简单方法!为此向 Spring Boot 致敬!!!
Of course you can continue to use Gradle for tasks like running all the tests or creating the packaged application.
当然,您可以继续使用 Gradle 执行诸如运行所有测试或创建打包应用程序之类的任务。
回答by Felipe S.
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.
我知道这个答案已经得到回答,但由于这是在 Google 中搜索时的第一个主题,我想分享一个我选择的替代方案,但在我阅读的其他主题中没有找到。
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. Basically:
为了避免这种情况,我使用spring-boot-devtools。基本上:
Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change.
每当 classpath 上的文件发生更改时,使用 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.xml
:
compile('org.springframework.boot:spring-boot-devtools')
I found this to be really useful in development.
我发现这在开发中非常有用。
回答by Vijayakumar S
I am using IntelliJ in Mac, running Spring boot application was giving the same issue. Whenever I run the app in Terminal and use CTRL + Z, the terminal will strop running the app. But when I run the app again in the same terminal, will give error saying the port 8080 was in use. 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.
我在 Mac 中使用 IntelliJ,运行 Spring 启动应用程序时遇到了同样的问题。每当我在终端中运行应用程序并使用 CTRL + Z 时,终端都会停止运行应用程序。但是当我在同一个终端中再次运行该应用程序时,会报错说端口 8080 正在使用中。我只是尝试了关闭终端会话的选项(右键单击 -> 选择 -> 关闭会话)。这将关闭终端,当我再次单击终端选项并运行应用程序时,它运行顺利。