Java Spring boot devtools - 静态内容重新加载在 IntelliJ 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35895730/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:14:13  来源:igfitidea点击:

Spring boot devtools - Static content reloading does not work in IntelliJ

javaspringintellij-ideaspring-boot

提问by Wouter

When building my first Spring Boot app, I discovered that I need to restart my app every time I make a change to a Javascript file in /resources/static/some-file.js

在构建我的第一个 Spring Boot 应用程序时,我发现每次更改 /resources/static/some-file.js 中的 Javascript 文件时都需要重新启动我的应用程序

This is very time consuming.

这是非常耗时的。

When I move the files to the /webapps/ folder, it works as expected, but the files are not packaged in a JAR. The docs mention this, so I cannot continue this way.

当我将文件移动到 /webapps/ 文件夹时,它按预期工作,但文件未打包在 JAR 中。文档提到了这一点,所以我不能继续这种方式。

I read all about spring-boot-devtools, and have installed it in my POM, but the hotswapping doesn't seam to be working. I still need to restart the entire app to see a Javascript or CSS file change.

我阅读了所有关于spring-boot-devtools,并已将其安装在我的 POM 中,但热插拔无法正常工作。我仍然需要重新启动整个应用程序才能看到 Javascript 或 CSS 文件的更改。

When the app starts, I can see the line LiveReload server is running on port 35729, so spring-boot-devtoolsmust be doing something...

当应用程序启动时,我可以看到这条线LiveReload server is running on port 35729,所以spring-boot-devtools一定是在做些什么......

What would be the steps to further investigate what is going wrong?

进一步调查出了什么问题的步骤是什么?

My guess is that when IntelliJ runs the app, the files are copied, so when I make a change, I'm actually changing the original files and not the ones used by the running app.

我的猜测是,当 IntelliJ 运行应用程序时,文件会被复制,所以当我进行更改时,我实际上是在更改原始文件,而不是正在运行的应用程序使用的文件。

PS: I'm using Maven, IntelliJ IDEA 15 and Spring Boot 1.3.3 with the embedded Tomcat server. I'm not sure what command IntelliJ runs to start the app. The IDE is handling this "automatically". Perhaps I need to change my run configuration?

PS:我将 Maven、IntelliJ IDEA 15 和 Spring Boot 1.3.3 与嵌入式 Tomcat 服务器一起使用。我不确定 IntelliJ 运行什么命令来启动应用程序。IDE 正在“自动”处理这个问题。也许我需要更改我的运行配置?

采纳答案by Patrick Grimard

You need to turn on a couple of features in IntelliJ to make this work.

您需要在 IntelliJ 中打开几个功能才能完成这项工作。

First, there's a project specific setting which you would need to apply on any project you want to use devtools in. Go to Preferences > Compiler and enable "Make project automatically."

首先,有一个特定于项目的设置,您需要将其应用于要在其中使用 devtools 的任何项目。转到 Preferences > Compiler 并启用“Make project automatically”。

The next setting is an IDEA registry setting that applies to all projects.

下一个设置是适用于所有项目的 IDEA 注册表设置。

  • In macOS (OSX), press Shift+Command+A(Shift+Ctrl+Ain Windows)
  • Type "Registry" in the search box that appears, and select the registry to open it.
  • Lookup compiler.automake.allow.when.app.runningand enable it.
  • 在 macOS (OSX) 中,按Shift+Command+A(Shift+Ctrl+A在 Windows 中)
  • 在出现的搜索框中键入“注册表”,然后选择注册表将其打开。
  • 查找compiler.automake.allow.when.app.running并启用它。

After that, restart your app. You will notice that the project keeps rebuilding with every change you make. When you check out the result in the browser, you will see both static files and code have been updated.

之后,重新启动您的应用程序。您会注意到,随着您所做的每一次更改,项目都会不断重建。当您在浏览器中查看结果时,您将看到静态文件和代码都已更新。

回答by Daniil Shevelev

For Windows users the steps are:
1) Go to File->Settings, then to "Build,Execution,Deployment"->Compiler and enable the "Make project automatically" flag.
2) Press Ctrl-Alt-Shift-/ and select "Registry" from the menu that appears. Enable compiler.automake.allow.when.app.running flag.
3) Start/restart the app and observe static content reloading.

对于 Windows 用户,步骤是:
1) 转到文件->设置,然后转到“构建、执行、部署”->编译器并启用“自动生成项目”标志。
2) 按 Ctrl-Alt-Shift-/ 并从出现的菜单中选择“注册表”。启用 compiler.automake.allow.when.app.running 标志。
3) 启动/重启应用程序并观察静态内容重新加载。

回答by raj vivid

For mac users I had to press Command+ Shift+ A

对于 mac 用户,我必须按Command+ Shift+A

And restart INTELLIJ after Step1 and Step2 without which the registry option was not appearing.

并在 Step1 和 Step2 之后重新启动 INTELLIJ,否则不会出现注册表选项。

回答by Anatolii Stepaniuk

On Linux, press:

在 Linux 上,按:

Ctrl-Alt-Shift-/

Ctrl- Alt- Shift-/