-
Notifications
You must be signed in to change notification settings - Fork 38.5k
ResourceHandlers cannot resolve static resources without wildcard patterns #29739
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
Comments
As the pic shows,the reason is that the attribute of |
This case can be reduced to a favicon file located in @Configuration
public class WebConfiguration implements WebFluxConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/en/favicon.ico").addResourceLocations("classpath:/static/");
}
} The This is not a problem on the MVC side, where the HTTP handling itself is slightly different and can use the full path. We're going to handle this as an enhancement, as backporting this change to 5.3.x has not been a problem so far and we want to avoid serving static resources that were ignored in the past. @mufasa1976 Note that your resource handling setup is quite inefficient, as it's registering many handlers for few resources; this might cause performance inefficiencies when handling HTTP requests. I'm not familiar with your constraints, but I would try in general to use a front-end build tool to pack and clean those resources, only leaving the ones you're expecting to be public. You could then try and reduce registrations just for supported languages: @Configuration
public class WebConfiguration implements WebFluxConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/en/**").addResourceLocations("classpath:/static/en/");
registry.addResourceHandler("/de/**").addResourceLocations("classpath:/static/de/");
}
} |
@bclozel: you are completely right. I've copied the Block from the SUPPORTED_LANGUAGE.forEach(locale -> registry.addResourceHandler("/" + locale.getLanguage() + "/**")
.addResourceLocations(prefix + locale.getLanguage() + "/")); Thank you for your Tip! |
The following Code-Snippet works correctly with Spring MVC:
I convert the Application to use Spring Web-Flux and rewrite the Configuration:
The rewritten Application is available via Github
When trying to access the Resource
/en/favicon.ico
I will receive a HTTP 404 Error while accessing the Resource/en/main.6187e65880c98290.js
will give me a HTTP 200 with the correct Content.The text was updated successfully, but these errors were encountered: