SpringBoot应用 Automatic Restart以及静态资源 livereload 设置

SpringBoot应用 Automatic Restart以及静态资源 livereload 设置
20.2 Automatic Restart
Applications that use spring-boot-devtools automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE, as it gives a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder is monitored for changes. Note that certain resources, such as static assets and view templates, do not need to restart the application.

当类路径上的文件发生变化时,使用spring-boot-devtools的应用程序会自动重启。 当在IDE中工作时,它为代码更改提供了一个非常快速的反馈循环,这是一个有用的功能。 默认情况下,路径下的所有条目都将被监视是否更改。 但是,某些时候,有些资源(如静态资产和视图模板)的更改不需要重新启动应用程序。

20.2.1 Excluding Resources
Certain resources do not necessarily need to trigger a restart when they are changed. For example, Thymeleaf templates can be edited in-place. By default, changing resources in /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates does not trigger a restart but does trigger a live reload. If you want to customize these exclusions, you can use the spring.devtools.restart.exclude property. For example, to exclude only /static and /public you would set the following property:

有些资源被更改时不需要触发服务重启。例如,Thymeleaf模板可以就地编辑而不触发服务重启。默认情况下,更改 /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates 这些目录下的资源不会触发重启。也可以通过设置spring.devtools.restart.exclude属性来自定义这些目录。例如,将 spring.devtools.restart.exclude 设置为如下可排除对
/static,/public 目录的restart监测。

spring.devtools.restart.exclude=static/**,public/**

20.2.3 Disabling Restart

If you do not want to use the restart feature, you can disable it by using the spring.devtools.restart.enabled property. In most cases, you can set this property in your application.properties (doing so still initializes the restart classloader, but it does not watch for file changes).

如果您不想使用重新启动功能,则可以使用spring.devtools.restart.enabled属性将其禁用。 在大多数情况下,您可以在application.properties中设置此属性(这样做仍会初始化重新启动类加载器,但不会监视文件更改)。

If you need to completely disable restart support (for example, because it doesn’t work with a specific library), you need to set the spring.devtools.restart.enabled System property to false before calling SpringApplication.run(…​), as shown in the following example:

如果您需要完全禁用重新启动支持(例如,因为它不适用于特定的库),则需要在调用SpringApplication.run(...)之前将spring.devtools.restart.enabled 系统属性设置为false, 如以下示例所示:

public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApp.class, args);
}


20.3 LiveReload
The spring-boot-devtools module includes an embedded LiveReload server that can be used to trigger a browser refresh when a resource is changed. LiveReload browser extensions are freely available for Chrome, Firefox and Safari from livereload.com.

spring-boot-devtools模块包含一个嵌入式LiveReload服务器,当资源发生变化时,可用于触发浏览器刷新。 LiveReload浏览器扩展支持的Chrome,Firefox和Safari,可从livereload.com免费获得。

If you do not want to start the LiveReload server when your application runs, you can set the spring.devtools.livereload.enabled property to false.

如果您不想在应用程序运行时启动LiveReload服务器,则可以将spring.devtools.livereload.enabled属性设置为false。

[Note]
You can only run one LiveReload server at a time. Before starting your application, ensure that no other LiveReload servers are running. If you start multiple applications from your IDE, only the first has LiveReload support.

一次只能运行一个LiveReload服务器。 在开始您的应用程序之前,请确保没有其他LiveReload服务器正在运行。 如果从IDE启动多个应用程序,则只有第一个支持LiveReload。

进行相关设置之前,要引入 spring-boot-devtools 依赖。

猜你喜欢

转载自blog.csdn.net/haiyoung/article/details/78595597
今日推荐