Given current efficiency impact of webjars-locator-core
(see this related comment), an its incompatibility with native images, it makes sense to recommend to use versioned URLs with this kind of configuration instead of WebJarsResourceResolver
without including webjars-locator-core
dependency in Spring reference documentation.
@Bean
public WebMvcConfigurer configurer() {
return new WebMvcConfigurer() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:META-INF/resources/webjars/");
}
};
}
We can refine later recommending the regular webjars-locator-core
+ WebJarsResourceResolver
approach with version-less URLs if/when webjars-locator-core
implement resource resolution without scanning, which seems to be possible as experimented in #27619.
Comment From: sdeleuze
Interestingly, WebJars versioned URLs work out of the box with Spring Boot which configures /META-INF/resources
resource location by default (at least for now, see spring-projects/spring-boot#28295 related issue) so no need for WebMvcConfigurer
bean for regular use case.
Comment From: vpavic
Did you consider linking to WebJars' own documentation, more specifically to its Spring MVC section?
It is a bit dated (I'll try to open a PR to address that) but it should cover everything.
Comment From: sdeleuze
Good point, feel free to provide a PR to refine.