Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring Boot开发工具/实时重新加载-静态资源刷新不起作用_Spring Boot_Gradle_Livereload_Spring Boot Devtools - Fatal编程技术网

Spring boot Spring Boot开发工具/实时重新加载-静态资源刷新不起作用

Spring boot Spring Boot开发工具/实时重新加载-静态资源刷新不起作用,spring-boot,gradle,livereload,spring-boot-devtools,Spring Boot,Gradle,Livereload,Spring Boot Devtools,为了提高开发人员的体验,我尝试使用Spring开发工具 我的设置: 多模块 梯度6.6 弹簧靴2.4.2 百里香 与子页面的网页包进行反应 我使用一个带有settings.gradle文件和一个子模块的多项目gradle构建,该子模块还具有spring bootbootJar。在build.gradle的文件中,我添加了developmentOnly(“org.springframework.boot:springbootdevtools”)行 IntelliJ配置 我通过IntelliJ启

为了提高开发人员的体验,我尝试使用Spring开发工具

我的设置:

  • 多模块
  • 梯度6.6
  • 弹簧靴2.4.2
  • 百里香
  • 与子页面的网页包进行反应
我使用一个带有
settings.gradle
文件和一个子模块的多项目gradle构建,该子模块还具有spring boot
bootJar
。在
build.gradle
的文件中,我添加了
developmentOnly(“org.springframework.boot:springbootdevtools”)

IntelliJ配置 我通过IntelliJ启动我的应用程序:

我还启用了“设置>编译器”设置中的“自动生成项目”以及“Compiler.automake.allow.when.app.running”

什么有效 启动应用程序时,我会看到日志消息

[2021-03-17 14:18:02.001]信息[restartedMain]——o.s.b.d.a.可选LiveReload服务器:LiveReload服务器正在端口35729上运行

声明我的LiveReloadServer已启动

当我在Java文件中应用更改时,会触发构建和重新启动,因此在更改时重新启动确实有效-尽管速度相当慢-即使我只更改Java类中的一行,重建至少需要15秒

什么不起作用 当我将更改应用于HTML、CSS或JS文件或react应用程序时,更改只会在重建项目后反映出来。我的所有资源都在默认的
resources/static
文件夹中,因此它们应该由dev tools reload处理

仅供参考,我将我的react应用程序打包为webpack,当我启动
webpack watch
任务时,每当我应用更改时,它都会正确地重建bundle.js

我有一个自定义ResourceRegistryHandler设置,可能这是问题的一部分,尽管我不理解为什么:

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {

        boolean devMode = this.env.acceptsProfiles(Profiles.of("dev"));
        boolean useResourceCache = !devMode;

        final String[] pathPatterns = Arrays.stream(RESOURCE_FOLDERS).map(f -> f + FOLDER_SUFFIX)
                    .toArray(String[]::new);

        final String[] resourceLocations = Arrays.stream(RESOURCE_FOLDERS).map(f -> CLASSPATH_PREFIX + f)
                .toArray(String[]::new);

        if (useResourceCache) {
            resourceProperties.getCache().setPeriod(Duration.of(365, ChronoUnit.DAYS));

            registry.addResourceHandler(pathPatterns)
                    .addResourceLocations(resourceLocations)
                    .setCachePeriod((int) Duration.of(365, ChronoUnit.DAYS).getSeconds())
                    .resourceChain(true)
                    .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"))
                    .addTransformer(new CssLinkResourceTransformer());
        } else {
            resourceProperties.getCache().setPeriod(Duration.of(0, ChronoUnit.DAYS));

            registry.addResourceHandler(pathPatterns)
                    .addResourceLocations(resourceLocations)
                    .setCachePeriod(0)
                    .resourceChain(false);
        }
    }
实时重新加载 除了静态资源尚未刷新之外,我还想知道如何使用live reload chrome插件,因为当我想启用live reload浏览器插件时,我总是会弹出一个弹出窗口,说明
无法下载livereload.js

我的问题
  • 如何让Spring刷新静态资源?他们甚至不会在我重新加载页面时刷新,只有在重启被触发并完成之后
  • 我怎样才能让它与实时重新加载一起工作

我也希望得到任何关于为什么我的项目构建即使有那么小的更改也会花费那么长时间的提示,我可能会检查gradle构建扫描以了解这一点。

我也在寻找这个问题的答案

我们让它为我们工作。我们不得不精简gradle构建,但现在它可以按预期工作-每当我们更改文件并在IntelliJ中按Ctrl+Shift+F9时,它都会在需要时重新启动服务器,或者在仅刷新静态资源时触发实时重新加载。只有在按下Ctrl+Shift+F9时,我才删除IntelliJ配置中的所有“更新类和资源”,因为它们太频繁地触发了重启。