Spring Boot 中的热交换 [英] Hot swapping in Spring Boot

查看:44
本文介绍了Spring Boot 中的热交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用 Spring Boot 做 P.O.C.

I've been doing a P.O.C with Spring Boot.

到目前为止,它的进展非常好,很有希望,但有一个主要缺点:我使用的是嵌入式服务器(即,将 Web 应用程序打包在 .jar 中),因此在开发时我每次更改 CSS、HTML 或 JS 文件时,都必须重建 jar 并重新启动服务器.没有热插拔.这确实减慢了 UI 的开发速度.

So far it's been going really good and promising, but there's one major drawback: I'm using an embedded server (i.e., packaging the web app in a .jar), so when developing I have to rebuild the jar and restart the server every time I change the CSS, HTML or JS files. There's not hot-swap. This really slows down the UI development.

我可以想到几个快速修复,例如从不同的域加载静态资源并从本地 nginx 提供服务,以及更多类似这样的变体,但没有内置的-在使用 IntelliJ/Eclipse 时可以选择某种方式吗?

I can think of several quick fixes, such as loading static resources off a different domain and serving it from a local nginx, and some more variations like this, but isn't there a built-in option of some sort when working with IntelliJ/Eclipse?

推荐答案

有几个选项.在 IDE 中运行(尤其是在调试时)是进行开发的好方法(所有现代 IDE 都允许重新加载静态资源,通常还可以热交换 Java 类更改).Spring Boot devtools 是一种获得相当大提升的廉价方法(只需将其添加到您的类路径中).它的工作原理是在检测到更改时在热 JVM 中重新启动应用程序.它还会在运行时关闭 thymeleaf 缓存之类的东西,因此您不必记住自己这样做.如果您使用更高级别的工具编写该代码,则可以将其与外部 css/js 编译器进程一起使用.

There are several options. Running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also hotswapping of Java class changes). Spring Boot devtools is a cheap way to get quite a big boost (just add it to your classpath). It works by restarting your application in a hot JVM when changes are detected. It also switches off things like thymeleaf caches while it is running, so you don't have to remember to do that yourself. You can use it with an external css/js compiler process if you are writing that code with higher level tools.

Spring Loaded 不再推荐,但可能仍在使用.如果您需要零延迟热插拔(例如 JRebel),更复杂的基于代理的工具会更好地工作.

Spring Loaded is no longer recommended, but probably still in use. More sophisticated agent-based tools work much better if you need hot swapping with zero delay (e.g. JRebel).

参见文档 一些最新的内容

这篇关于Spring Boot 中的热交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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