SpringBoot官方文档翻译(二十五):使用触发文件&定制“重启”类加载器

20.2.5 Using a Trigger File(使用触发文件)

1
2
3
4
5
6
7
If you work with an IDE that continuously compiles changed files,     
you might prefer to trigger restarts only at specific times. To do
so, you can use a “trigger file”, which is a special file that must
be modified when you want to actually trigger a restart check.
Changing the file only triggers the check and the restart only occurs
if Devtools has detected it has to do something. The trigger file can
be updated manually or with an IDE plugin.

如果您使用持续编译更改文件的IDE,您可能更愿意仅在特定时间触发重新启动。如果那样的话,您可以使用一个“触发文件”,当您需要触发重启的时候,您必须通过修改这个特殊的文件触发。这个文件的改变仅仅触发检查并且只是重启Devtools已经发现需要做的一些事情。这个触发文件能够被手动更新或者通过IDE的插件更新。

1
2
To use a trigger file, set the spring.devtools.restart.trigger-file     
property to the path of your trigger file.

想使用这个触发文件,设置spring.devtools.restart.trigger-file属性到您的触发文件。

1
2
You might want to set spring.devtools.restart.trigger-file as     
a global setting, so that all your projects behave in the same way.

您也许想要设置set spring.devtools.restart.trigger-file为一个全局的设置,那样的话您所有的项目都能通过这样的方式统一行为。

20.2.6 Customizing the Restart Classloader(自定义重启类加载器)

1
2
3
4
As described earlier in the Restart vs Reload section, restart     
functionality is implemented by using two classloaders. For most
applications, this approach works well. However, it can sometimes
cause classloading issues.

如前重启和重载章节所述,重启功能是由两个类加载器来实现的。对于大多数应用,这种方式工作正常。然而,它有时候也会导致一些类加载问题。

1
2
3
4
5
By default, any open project in your IDE is loaded with the “restart”     
classloader, and any regular .jar file is loaded with the “base”
classloader. If you work on a multi-module project, and not every
module is imported into your IDE, you may need to customize things.
To do so, you can create a META-INF/spring-devtools.properties file.

默认情况下,任何您使用IDE打开的项目都是被“重启”类加载器加载,并且任何常规的.jar文件都会被“base”类加载器加载。如果您在一个多模块工作的项目中,并且并不是所有的模块都是导入到您的IDE,您也许需要定制一些东西。为此,您可以创建一个META-INF/spring-devtools.properties文件。

1
2
3
4
5
6
7
The spring-devtools.properties file can contain properties     
prefixed with restart.exclude and restart.include. The include 
elements are items that should be pulled up into the “restart”
classloader, and the exclude elements are items that should be
pushed down into the “base” classloader. The value of the property
is a regex pattern that is applied to the classpath, as shown in
the following example:

spring-devtools.properties文件能够包含前缀为restart.excluderestart.include属性。include元素项目将会被拉取到“重启”类加载器中,“exclude”元素项目将会提交至“base”类加载器。这些属性的值是一个应用于类路径的正则表达式模式,如下:

1
2
restart.exclude.companycommonlibs=/mycorp-common-[\\w-]+\.jar
restart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jar

1
2
All property keys must be unique. As long as a property     
starts with restart.include. or restart.exclude. it is considered.

所有的属性keys必须是唯一的。只要属性的前置是restart.include或者restart.exclude就会被考虑到。

1
2
3
All META-INF/spring-devtools.properties from the classpath are loaded.     
You can package files inside your project, or in the libraries that
the project consumes.

所有类路径下的META-INF/spring-devtools.properties都将会被加载。您可以打包文件进入您的项目或者在项目依赖的lib库中。

分享到