简体   繁体   中英

Spring boot web configuration

I've configured in my spring boot project (code provides most interesting part)

public class WebConfiguration extends WebMvcConfigurerAdapter {
  // ...
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("googleb54ababeddd1718e.html")
            .addResourceLocations("classpath:/static/googleb54ababeddd1718e.html");
    registry.addResourceHandler("google7160e5f82e26983b.html")
            .addResourceLocations("classpath:/static/google7160e5f82e26983b.html");
    registry.addResourceHandler("google06bd5e270f77943e.html")
            .addResourceLocations("classpath:/static/google06bd5e270f77943e.html");
    //...
  }

this configuration works fine. If you've payed your attention, some resources different, but can be grouped by mask and handler. File names: googleb54ababeddd1718e.html , google7160e5f82e26983b.html , google06bd5e270f77943e.html . So I've tried next part:

public class WebConfiguration extends WebMvcConfigurerAdapter {
  // ...
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("google.html")
            .addResourceLocations("classpath:/static/google*.html");
    //...
  }

and this case does not work. I believe I very close to correct solution, but I can't detect one. Can someone provide fix of this issue or explain why the approach is incorrect?

v1 Move all google** files to google folder and remove google prefix.

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/google/**")
            .addResourceLocations("classpath:/static/");
}

v2

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/{google**.html}")
        .addResourceLocations("classpath:/static/");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM