-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
ResourceHttpRequestHandler throwing IllegalArgumentException if resource doesn't end with slash breaks some third-party libraris #33815
Comments
Hi @jhoeller, IMHO I thik that this kind of issue should be fixed (or handled) by framework otherwise, waiting for the update of all other possible third part libraries can cause the biblical time to make the new version usable easily. I totally agree about notNull, but killing everything for a "/" that can easily be handled by code (perhaps logging a KR. Giuseppe. |
Thanks for raising this @milazzo-g @cagliostro92 and sorry for the inconvenience. This is the intent behind #33712. Previous behaviorLet's take an example application here, a simple Spring Boot application that contributes the following: import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration(proxyBeanMethods = false)
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/webjars/camunda");
}
} with the following structure under
Here are a few requests showing the previous behavior in this situation: The intended configuration doesn't work:
You'll need to change the request path to make it work:
You can't resolve other resources because Spring prevents escaping the configured location:
See logs:
If we were to try the same using the Spring Boot auto-configuration and configuration properties: spring.web.resources.static-locations=classpath:/META-INF/resources/webjars/camunda This would work because Spring Boot would automatically suffix the given location with a Possible outcomes
I don't think we can do that, as this would silently break existing applications. "GET /camunda/camunda.txt" would not work anymore. From our experience, adding a WARN log doesn't change the experience and developers won't act on it. This will be raised as a regression.
This is inconvenient, but this signals invalid configuration to developers and acting on it is easy enough and is likely to fix issues with the application. In the case of the Camunda starter, I guess the issue comes from here? In this case, I'm wondering if the I would really like to improve the upgrade experience here, but we're stuck between a silent behavior change that will break applications and a noisy (but healthy) exception during starting pointing to a likely invalid setup. |
Originally raised in spring-projects/spring-boot#42929 by @milazzo-g. This looks like a problem introduced by #33712, but I'm not sure if the fix should be in framework or the third-party library.
During context loading the
ResourceHttpRequestHandler
class scans all possible paths and if these do not end with "/" anIllegalArgumentException
type exception is thrown with message "Resource location does not end with slash: …" (seeResourceHttpRequestHandler@282
the call toResourceHttpRequestHandler::assertLocationPath
) this cause several issue with various jar included (in our casecamunda-webapp-webjar
7.22.0 - included bycamunda-bpm-spring-boot-starter-root
7.22.0).The path provided by the library is "classpath:/META-INF/resources/webjars/camunda" which as you can see does not contain the final "/". makes it unusable with
spring-boot
6.2.0-RC3.We temporary fixed creating a copy of
org.springframework.web.servlet.resource.ResourceHttpRequestHandler
in our src folder and modifying starting from line 282 from:ResourceHandlerUtils.assertLocationPath(location);
to:
this solved the issue. Could you please fix it in a next minor?
KR.
Giuseppe.
STACKTRACE.txt
The text was updated successfully, but these errors were encountered: