Java Spring Boot开发工具如何在独立模块中重新加载Maven多个依赖模块?

Java Spring Boot开发工具如何在独立模块中重新加载Maven多个依赖模块?,java,spring,maven,spring-boot,spring-boot-devtools,Java,Spring,Maven,Spring Boot,Spring Boot Devtools,我有一个具有以下结构的多模块Maven: app-parent -------app-library (Hibernate data entities layer) -------app-main (contains app-library as dependency), Spring Boot web application. 这些文件夹的简单pom.xml文件: app parent/pom.xml 另外,在app main/src/main/resources的applica

我有一个具有以下结构的多模块Maven:

app-parent
  -------app-library (Hibernate data entities layer)
  -------app-main (contains app-library as dependency), Spring Boot web application.
这些文件夹的简单pom.xml文件:

  • app parent/pom.xml
另外,在app main/src/main/resources的application.properties中,我添加了这个手表,以允许Spring开发工具检测来自app库的更改

spring.devtools.restart.additional-paths=../app-library
因此,每当我在appmain或applibrary中更改一个java文件时,我都可以从终端上看到springdevtool在几秒钟内完成重新加载

     .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.2.RELEASE)

  INFO [08:57:20] ApplicationMain@48: Starting ApplicationMain on localhost.localdomain with PID 19645 (/home/rasdaman/rasdaman_community/build/applications/petascope/target/petascope_main/classes started by rasdaman in /home/rasdaman/rasdaman_community/rasdaman/applications/petascope/petascope_main)
 DEBUG [08:57:20] ApplicationMain@51: Running with Spring Boot v1.5.2.RELEASE, Spring v4.3.7.RELEASE
  INFO [08:57:20] ApplicationMain@637: No active profile set, falling back to default profiles: default
[2018-05-01 08:57:22.341] - 19645 INFO [restartedMain] --- org.apache.catalina.core.StandardService: Starting service Tomcat
[2018-05-01 08:57:22.341] - 19645 INFO [restartedMain] --- org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat/8.5.11
[2018-05-01 08:57:22.361] - 19645 INFO [localhost-startStop-1] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/rasdaman]: Initializing Spring embedded WebApplicationContext
  INFO [08:57:24] ApplicationMain@57: Started ApplicationMain in 3.612 seconds (JVM running for 84.418)
问题在于app library方法中的一些基本更改,Spring DevTools可以检测到文件已保存并重新加载,但从调用此方法的app main中,输出仍然相同,例如:

app-library
public class Service {
     public String returnValue() {
          // return "Value before Spring DevTools reload.";

          // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          // After app-main was set up from Maven command lines, I changed this line here and saved it to notice Spring DevTool to reload in the console.
          return "Value after Spring DevTools reload."
     }
}

app-main
public class TestService {

    public TestService() {
         Service service = new Service();
         // !!!!!!!!!!!!!!!!!!!
         // It can only print "Value before Spring DevTools reload."
         // even though the Service file has been changed to return different value and Spring DevTools reloaded.
         System.out.println(service.returnValue());
    }
}
有了这个问题,我不能仅仅在应用程序库中更改,而期望更改将应用于应用程序主应用程序。相反,我必须停止Maven命令行,然后在NetBeans中单击app main并选择Build with dependencies,然后再次运行Maven命令行以使用冷启动设置此Web应用程序(总时间:~1分钟)


在我将文件保存到应用程序库中后,如何使Spring DevTools能够立即将更改从应用程序库应用到应用程序主应用程序?这将有助于减少NetBeans“使用依赖项构建”的等待时间。因此,在app main中,它需要在本地存储库中构建应用程序库(~/.m2/…),更新此存储库的唯一方法是转到应用程序库文件夹并运行:

mvn install
然后,从命令行(ctrl+c)停止正在运行的Web应用程序,并在app main文件夹上使用相同的maven命令重新启动它:

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

冷重启app main仍然需要时间,但这是可以接受的。

据我所知,spring boot开发工具只能在您只有一个模块的情况下处理这种情况……但据我所知,您可以配置要观察的目录……这应该可以解决问题……@khmarbaise我添加了要观察的应用程序库,但无法重新加载更改。没问题。您从项目的哪个级别启动了您的
mvn spring boot:run..
?@khmarbaise on app main folder。是否有任何更新?
     .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.2.RELEASE)

  INFO [08:57:20] ApplicationMain@48: Starting ApplicationMain on localhost.localdomain with PID 19645 (/home/rasdaman/rasdaman_community/build/applications/petascope/target/petascope_main/classes started by rasdaman in /home/rasdaman/rasdaman_community/rasdaman/applications/petascope/petascope_main)
 DEBUG [08:57:20] ApplicationMain@51: Running with Spring Boot v1.5.2.RELEASE, Spring v4.3.7.RELEASE
  INFO [08:57:20] ApplicationMain@637: No active profile set, falling back to default profiles: default
[2018-05-01 08:57:22.341] - 19645 INFO [restartedMain] --- org.apache.catalina.core.StandardService: Starting service Tomcat
[2018-05-01 08:57:22.341] - 19645 INFO [restartedMain] --- org.apache.catalina.core.StandardEngine: Starting Servlet Engine: Apache Tomcat/8.5.11
[2018-05-01 08:57:22.361] - 19645 INFO [localhost-startStop-1] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/rasdaman]: Initializing Spring embedded WebApplicationContext
  INFO [08:57:24] ApplicationMain@57: Started ApplicationMain in 3.612 seconds (JVM running for 84.418)
app-library
public class Service {
     public String returnValue() {
          // return "Value before Spring DevTools reload.";

          // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          // After app-main was set up from Maven command lines, I changed this line here and saved it to notice Spring DevTool to reload in the console.
          return "Value after Spring DevTools reload."
     }
}

app-main
public class TestService {

    public TestService() {
         Service service = new Service();
         // !!!!!!!!!!!!!!!!!!!
         // It can only print "Value before Spring DevTools reload."
         // even though the Service file has been changed to return different value and Spring DevTools reloaded.
         System.out.println(service.returnValue());
    }
}
mvn install
mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"