spring - 如何在 IntelliJ 的 Spring Boot 项目中使用实时编辑

标签 spring intellij-idea thymeleaf liveedit

我是网络开发新手。我发现 IntelliJ 中的实时编辑功能非常有用。我的问题是,我正在为 Spring Boot 项目开发 thymeleaf 页面,但无法进行实时编辑。

如果我创建一个静态 Web 项目并创建一个 html 文件,我可以右键单击该文件并单击 Debug模式,实时编辑将开始,并且 chrome 将开始使用 IntelliJ。但在 Spring 项目中,右键单击不会给我调试 html 文件的选项。如果我在 Chrome 中打开文件,右键单击页面并选择“在 IDEA 中检查”,它将与 IntelliJ 连接,但每次我对文件进行更改时,我都必须刷新浏览器才能获取更改。

我没有安装任何插件。我今天下载了 IntelliJ Ultimate,它带有实时编辑功能,我刚刚启用了它。

有没有办法只调试 Spring 项目中的 html 文件?或者有什么解决办法吗?

最佳答案

这就是 spring-boot-devtoolsLiveReload 来解决的问题

Applications that use spring-boot-devtools automatically restart whenever files on the classpath chang more info here

首先将其添加到您的 pom 文件中:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Gradle

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

Spring 使用重启技术来加快重新加载速度。但默认情况下,对 resources 文件夹的更改不会触发重新启动。这时 Spring 的人们想到了包括

an embedded LiveReload server that can be used to trigger a browser refresh when a resource is changed.

要充分利用此功能,您需要从 livereload.com 下载扩展程序您安装在浏览器中或只是通过 google 搜索它(例如 livereload chrome)。

通过单击启用扩展:启用 LiveReload

enable extension

现在,每当您对 html 文件进行任何更改时,都会自动检测到更改并反射(reflect)在您的浏览器上。

关于spring - 如何在 IntelliJ 的 Spring Boot 项目中使用实时编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51165677/

相关文章:

git - 在 intellij - Git 中填充新的远程分支

java - 单选按钮标签更改

java - Spring Cloud AWS SQS 监听器不工作

spring - Drools 和 Camel : Failed to load type converters Cannot find any type converter classes [org. drools.camel.component]

spring - 为什么Spring AOP在某些情况下会拦截 protected 方法?

java - 如何为基于gradle的Google App Engine项目在IntelliJ中启用带有断点的调试?

java - IntelliJ : (Keyboard shortcut to) jump to next/previous suggestion

java - Thymeleaf 和带指纹的静态资源

java - 使用 Spring 将数据从 Thymeleaf 传递到 Controller

node.js - 无法使用 Spring Boot 运行 VueJS SPA