Spring boot devtools - 静态内容重新加载在IntelliJ中不起作用 [英] Spring boot devtools - Static content reloading does not work in IntelliJ

查看:502
本文介绍了Spring boot devtools - 静态内容重新加载在IntelliJ中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这非常耗时。

当我将文件移动到/ webapps /文件夹时,它按预期工作,但文件未打包在一个罐子里。文档提到了这一点,所以我不能这样继续。

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.

我读了所有关于 spring-boot-devtools ,并已将其安装在我的POM中,但是hotswapping不能正常工作。我仍然需要重新启动整个应用程序以查看Javascript或CSS文件更改。

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.

当应用程序启动时,我可以看到行 LiveReload服务器正在端口35729 上运行,所以 spring-boot-devtools 必须做某事......

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

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

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

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

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.

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

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?

推荐答案

您需要在IntelliJ中启用一些功能才能使其正常工作。

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

首先,您需要在任何想要使用devtools的项目中应用项目特定设置。转到首选项>编译器并启用自动生成项目。

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."

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

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


  • 在OSX中,按 Shift + Command + A 在Windows中按Shift + Ctrl + A

  • 在出现的搜索框中键入注册表,然后选择注册表将其打开。

  • 查找 compiler.automake.allow.when.app.running 并启用它。

  • In OSX, press Shift+Command+A (Shift+Ctrl+A in Windows)
  • Type "Registry" in the search box that appears, and select the registry to open it.
  • Lookup compiler.automake.allow.when.app.running and enable it.

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

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.

我不久前还撰写了一篇关于此内容的博文。
http://patrickgrimard.com/2016 / 01/18 / spring-boot-devtools-first-look /

I also wrote a blog post about this a little while ago. http://patrickgrimard.com/2016/01/18/spring-boot-devtools-first-look/

这篇关于Spring boot devtools - 静态内容重新加载在IntelliJ中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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