spring-boot-devtools重新加载多模块Maven项目更改 [英] spring-boot-devtools reload of multi-module maven project changes

查看:526
本文介绍了spring-boot-devtools重新加载多模块Maven项目更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一个多模块的Maven项目.项目结构为:

Imagine a multi-module maven-project. The project structure is:

pom.xml //parentpom
   |
  pom.xml //submodule_1
   |
  pom.xml //submodule_2
   .
   .
   .
  pom.xml //submodule_7

例如,submodule_5具有submodule_6和submodule_7作为依赖项.可以构建submodule_5来构造可以部署的War文件. Spring-Boot-Devtools 提供了每当对classmodule的submodule_5进行更改时自动重启的功能.

For example submodule_5 has submodule_6 and submodule_7 as dependencies. The submodule_5 can be build to construct a War-file which can be deployed. Spring-Boot-Devtools provide the feature of automatic-restart whenever there is a change to submodule_5 it's classpath.

每当使用以下命令运行应用程序时:

Whenever the application is run using:

mvn spring-boot:run

然后对submodule_5进行更改(取决于使用类路径的IDE更改.(对于 Eclipse 自动/对于 InteliJ ,当按 Ctrl + F9 ))spring-boot自动重启应用程序并添加更改. submodule_6或submodule_7发生的更改不会触发自动重启.

And changes are made to submodule_5 (depending on which IDE you use the classpath get changed. (for Eclipse automaticaly / for InteliJ when pressing Ctrl+F9)) spring-boot automaticaly restarts the application and changes are added. Changes which happen to submodule_6 or submodule_7 don't trigger the automatic restart.

  1. 是否有办法做到,每当您在submodule_6或submodule_7中进行更改时,使它们强制重新启动并因此应用更改?
  2. Spring-boot-devtools使用两个类加载器:基础类加载器"& 重启类加载器".是否在应用程序初始启动时将submodule_6和submodule_7添加到基础类加载器"中,而submodle_5保留在重新启动类加载器"中?是否可以使submodule_5每次强制重新启动时都使用基础类加载器"中的submodule_6和submodule_7版本?

推荐答案

为解决此问题,我开始从 InteliJ 中运行该应用程序.无需添加.

To fix this problem I started running the application from within InteliJ. without having to add.

spring.devtools.restart.additional-paths=../submodule_6,../submodule_7

IntelliJ spring-boot 看起来很不错.首先,它对我不起作用的原因是因为我最初是从命令行进行工作.

IntelliJ and spring-boot seem to work together very wel. The reason it was not working for me in the first place was because I was working from the commandline at first.

因此 spring-boot-devtools 使用两个类加载器来加载应用程序. Jar将在基础类加载器"中 ones 加载,您的应用程序将在重新启动类加载器"中加载.每当类路径发生变化时,最后一个类加载器将重新启动.

So spring-boot-devtools uses two classloaders to load an application. Jars will be loaded ones in the "Base classloader", your application will be loaded in the "restart classloader". This last classloader will restart everytime there is a change on the classpath.

每当从命令行运行submodule_5时,它将构建submodule_6和submodule_7并将jar添加到submodule_5的构建中.每当在submodule_6和submodule_7中进行更改时,spring-boot甚至都不会注意到,因为它仅监视submodule_5并具有所需的jar.即使您明确要求它也监视那些子模块,它仍然不会重建它们,它只会继续使用已经在基本类加载器"中加载的jar(这是我的假设,我不是100 %确定其运作方式.

Whenever running submodule_5 from the commandline, it will build the submodule_6 and submodule_7 and add the jars to the build of submodule_5. Whenever changes are made in submodule_6 and submodule_7 spring-boot won't even notice since it's only watching submodule_5 and has the jars it needs. Even if you would specifically tell it to also watch those submodules, it still won't rebuild those, it'll just keep using the jars it already has loaded in the "base classloader" (This is my assumption, I'm not 100% certain of the way it works).

每当从IDE中运行submodule_5时,它都不会创建submodule_6和submodule_7的jar.它将仅使用其classpath.这样一来,您的intire项目的classpath(所有子模块)中的更改将触发自动重启并应用更改.

Whenever running submodule_5 from the IDE, it won't create the jar of the submodule_6 and submodule_7. It will just use their classpath. This makes it so that changes in your intire project's classpath (all submodules) will trigger the automatic restart and the changes will be applied.

额外

每当从IDE运行时,都会更改为html-files,css-files,xml-files之类的资源. . .不会触发重新启动,因为这不是类路径中的更改.但是更改仍然可见.

Whenever running from the IDE changes to resources like html-files, css-files, xml-files . . . won't trigger a restart since this is not a change in the classpath. But the changes will still be visible.

这篇关于spring-boot-devtools重新加载多模块Maven项目更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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