【问题标题】:How to live reload without restart on additional static resources in spring boot?如何在spring boot中重新加载其他静态资源而不重新启动?
【发布时间】:2018-07-07 10:44:52
【问题描述】:

我正在尝试在启用了实时重新加载但不启用应用程序重新启动的 Spring Boot 项目上设置新的资源位置。我可以添加其他资源,但是在新目录中所做的任何更改都会导致应用程序重新启动。

上面的documentation 看起来很轻。我一定是误解了什么。

我的布局是这样的:

- src
  - main
    - java
    - resources
      - static
- web
  - dist 

我的应用程序类如下所示:

    @Bean
    WebMvcConfigurer configurer () {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addResourceHandlers (ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/dist/**")
                    .addResourceLocations(""file:web/dist/"")
                    .setCachePeriod(0);
            }
        };
    }

    public static void main(String[] args)
    {
        SpringApplication app = new SpringApplication(Application.class);
        app.addListeners(new PropertyLogger());

        Properties properties = new Properties();
        properties.setProperty("spring.devtools.restart.additional-paths", "web/dist/");
        properties.setProperty("spring.devtools.restart.additional-exclude", "/dist/**");
        app.setDefaultProperties(properties);

        app.run(args);
    }

我已经阅读了几个类似的问题,这似乎是我能做的最好的。是否可以在没有完全重新启动应用程序的情况下在 dist 上启用实时重新加载?

顺便说一下,我的 IDE 是 IntelliJ。我开始怀疑 IntelliJ 是否需要排除 dist 目录。如果是这样,我会跟进。

【问题讨论】:

    标签: spring-boot livereload


    【解决方案1】:

    我已经把它打死了,终于找到了一个可行的解决方案。

        Properties properties = new Properties();
        properties.setProperty("spring.devtools.restart.additional-paths", "web/");
        properties.setProperty("spring.devtools.restart.additional-exclude", "dist/**");
        app.setDefaultProperties(properties);
    

    将 web 目录定义为附加路径并结合用于附加排除的模式可以解决问题。

    除非有人支持我的结论,否则我不会将此标记为已接受。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多