Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use WebJars without webjars-locator-core dependency #29322

Closed
sdeleuze opened this issue Oct 14, 2022 · 3 comments
Closed

Document how to use WebJars without webjars-locator-core dependency #29322

sdeleuze opened this issue Oct 14, 2022 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: documentation A documentation task
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Oct 14, 2022

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.

@sdeleuze
Copy link
Contributor Author

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.

@sdeleuze sdeleuze modified the milestones: 6.0.0-RC2, 5.3.24 Oct 16, 2022
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Oct 16, 2022
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Oct 16, 2022
@vpavic
Copy link
Contributor

vpavic commented Oct 17, 2022

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.

@sdeleuze
Copy link
Contributor Author

Good point, feel free to provide a PR to refine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

2 participants