-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Refine location checks for PathResource #34167
Comments
This is also blocking us from upgrading to Spring Framework 6.2 Our config looks like @Configuration
public class WebMvcConfigurationDev implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/messages/*")
.addResourceLocations(new ClassPathResource("/"))
.resourceChain(false)
.addResolver(new MessagesResolver())
.addTransformer(new MessagesTransformer());
}
} which we use to resolve message bundles from the classpath. |
Thanks for reaching out. I guess we can refine checks for specific resource implementations. For your case @stewue, the PathResource pathResource = new PathResource("/static");
Resource other = pathResource.createRelative("other.txt");
// will yield "/static/other.txt" So I think that we should generally leave Now for @tompson 's case, the I'll discuss this with the web team and report back here. |
ResourceHandlerRegistration.addResourceLocations(Resource...)
throws IllegalArgumentException
with 6.2.x
We have discussed this today, here are our conclusions. We are repurposing this issue to refine the location checks to account for the As for the |
The "status: backported" label doesn't seem to be valid as #34213 has been closed as invalid. |
@bclozel ok, thanks for looking into this, we decided to move the files into a |
Hi,
I have currently have a Spring Boot application using Spring Framework 6.1. I tried to upgrade to the newest Spring Boot and Framework version. During upgrading I realized that in my implemented
WebMvcConfigurer
now anIllegalArgumentException
is thrown.Here a minimal example on how you can reproduce it:
In the example a
Caused by: java.lang.IllegalArgumentException: Resource location does not end with slash: /demo-directory
is thrown. The issue is that in 59ec871 an additional check was added inResourceHandlerUtils
. All constructors ofPathResource
callPath.normalize
which removes the passed trailing slash.I know in this minimal example just
ResourceHandlerRegistration.addResourceLocations(String...)
can be used. However in reality I'm dynamically adding different resources in a multi module project.Is this an undesirable side effect of #33815 or how should
ResourceHandlerRegistration.addResourceLocations(Resource...)
be used withPathResource
?Thank you in advance!
The text was updated successfully, but these errors were encountered: