Spring Boot + Spring-Loaded(IntelliJ,Gradle) [英] Spring Boot + Spring-Loaded (IntelliJ, Gradle)

查看:132
本文介绍了Spring Boot + Spring-Loaded(IntelliJ,Gradle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Spring Boot项目中使用热插拔.尽管

I'd like to use hot swap with my Spring Boot project. Somehow I am not able to make it working by running it in my IDE (IntelliJ), despite of having this topic covered by documentation. I simply run the class with my main method with VM attributes:

-javaagent:/path/to/jar/springloaded.jar -noverify

我的问题是,如何使它工作? :-)

My question is, how do I make it work? :-)

进一步的问题是如何使用Gradle和IntelliJ加载的弹簧.我发现强迫开发人员手动下载JAR,将其放在某个位置并使用JVM参数指向它非常不方便.有什么更好的方法(我应该配置自己的任务来完成工作,并从我的IDE作为Gradle任务运行它)吗?

Further question is how to use spring loaded with Gradle and IntelliJ. I find it quite inconvenient to force the developer to download the JAR manually, place it somewhere and point to it with a JVM parameter. Is there any better way (should I configure my own task which does the job and run it from my IDE as a Gradle task)?

推荐答案

您需要按照文档中的说明配置项目:

You need to configure the project as stated in the documentation:

在那之后,您必须配置IDE以在build/classes/main中输出编译的类(使用Idea插件,您可以按照上述链接中的配置配置outputDir,然后调用gradle idea来完成此操作) .

After that, you must configure your IDE to output the compiled classes in build/classes/main (with Idea plugin, you can configure the outputDir as specified in the above link, and then invoke gradle idea to have it done).

然后,如果您使用调试模式启动任务(运行/bootRun)或从IDE的主类运行该类,则在编译时,应该可以重新加载热代码.

Then, if you launch the task (run / bootRun) or run the main class from the IDE's using the debug mode, hot code reloading should work when a class is compiled.

这里的问题是,与Eclipse不同,IntelliJ在保存类时不会自动编译一个类(即使将编译器配置为基于保存构建",在运行/调试时也不会这样做) .这显然是IntelliJ做出的设计决定-如此处 Intellij所述IDEA Java类无法在保存时自动编译(CrazyCoder答案).

The gotcha here is that IntelliJ, unlike Eclipse, doesn't automatically compile a class when it is saved (even if you configure the compiler to "Build on save", it won't do it when is Running/Debugging). This is apparently a design decission made by IntelliJ - as stated here Intellij IDEA Java classes not auto compiling on save (CrazyCoder answer) .

如果spring boot提供一个配置选项来监视您的源代码文件并在它们更改时重新编译它们,那将是理想的-这就是Grails所做的.但是我认为这样的想法还不存在,甚至可能无法将它与gradle结合使用,gradle负责管理类路径和类似的事情.

It would be ideal if spring boot provided a configuration option to monitor your source code files and recompile them when they change - that is what Grails does. But I think such a think does not exist yet, and maybe is not even possible to combine that with gradle, which is the responsible of managing the classpath and that kind of things.

据我所知,有两种选择:

So there are two options as far as I can tell:

  • 您记得要编译所有编辑内容(按照前面的StackOverflow链接中的建议添加一个更简单的Compile快捷方式可能会有所帮助).
  • 您放置了一些文件系统监视器(例如Linux的inotify-tools,是在Mac OS X上启动的示例),当在任何源代码文件中检测到更改时,它们就会调用gradle compileJava/compileGroovy.

首先是乏味的,其次是缓慢的:).实际上,还有另一个选择:您更改IDE :-D(或安装EclipseMode IntelliJ插件).

First is tedious, second is slow :) . Actually there's another option: you change your IDE :-D (or install the EclipseMode IntelliJ plugin).

这篇关于Spring Boot + Spring-Loaded(IntelliJ,Gradle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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