Skip to content

SpringWolf-UI's resourceHandler breaks existing resourceHandlers #1425

@rfelgent

Description

@rfelgent

Describe the bug
After adding SpringWolf-UI to one of my apps, the "static resource caching" is broken.
It seems to me the SpringwolfUiResourceConfigurer is causing this issue by adding its own resourceHandlers()

   @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String springwolfBasePath = springwolfConfigProperties.getPath().getBase();

        log.debug("Serving Springwolf with base-path: {}", springwolfBasePath);

        registry.addResourceHandler(springwolfBasePath + "/**", webMvcProperties.getStaticPathPattern())
                .addResourceLocations(buildStaticLocation());
    }

And re-applying webMvcProperties.getStaticPathPattern() in SpringWolf' overwrites the staticPathPattern within WebMvcAutoConfiguration and therefore turns off the static resource caching, e.g.

...
@Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
      if (!this.resourceProperties.isAddMappings()) {
        logger.debug("Default resource handling disabled");
      } else {
        this.addResourceHandler(registry, this.mvcProperties.getWebjarsPathPattern(), "classpath:/META-INF/resources/webjars/");
        this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (Consumer)((registration) -> {
          registration.addResourceLocations(this.resourceProperties.getStaticLocations());
          if (this.servletContext != null) {
            ServletContextResource resource = new ServletContextResource(this.servletContext, "/");
            registration.addResourceLocations(new Resource[]{resource});
          }

        }));
      }
    }
...
private void addResourceHandler(ResourceHandlerRegistry registry, String pattern, Consumer<ResourceHandlerRegistration> customizer) {
      if (!registry.hasMappingForPattern(pattern)) {
        ResourceHandlerRegistration registration = registry.addResourceHandler(new String[]{pattern});
        customizer.accept(registration);
        ////////////////////////////////////////////////////////////////////////////
        // this cache config is getting lost because of SpringWolf
        ////////////////////////////////////////////////////////////////////////////
        registration.setCachePeriod(this.getSeconds(this.resourceProperties.getCache().getPeriod()));
        registration.setCacheControl(this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl());
        registration.setUseLastModified(this.resourceProperties.getCache().isUseLastModified());
        this.customizeResourceHandlerRegistration(registration);
      }
    }
...

Dependencies and versions used

  • springwolf-amqp version 1.17.0
  • springwolf-ui version 1.17.0
  • spring-boot version 3.5

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions