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

FileSystemResource location does not end with slash for RouterFunction check #34509

Closed
ecabrera78 opened this issue Feb 27, 2025 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@ecabrera78
Copy link

I migrated an application from spring-boot 3.3.6 to 3.4.2. We have below code to create a static resource locator:

@Bean
RouterFunction staticResourceLocator() {
  return RouterFunctions.resources("/**", new FileSystemResource("/opt/cfg/static/"));
}

After the migration this code is throwing an exception:
Failed to instantiate [org.springframewok.we.reactive.function.server.RouterFunction]: Factory method 'stticResourceLocator' threw exception with message: Resource location does not end with slash: /opt/cfg/static

I found that when FileSystemResource is created there is a call to StringUtils.cleanPath(path) where the last slash is removed from the original path.

is there another way to create the FileSystemResource and preserve the last slash?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 27, 2025
@jhoeller jhoeller changed the title Resource location does not end with slash FileSystemResource location does not end with slash for RouterFunction check Mar 4, 2025
@jhoeller jhoeller self-assigned this Mar 4, 2025
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 4, 2025
@jhoeller jhoeller added this to the 6.2.4 milestone Mar 4, 2025
@jhoeller
Copy link
Contributor

jhoeller commented Mar 4, 2025

It's not actually StringUtils.cleanPath itself, it's the getURL().getPath() check that we do for Resource there. Like for ClassPathResource, we should explicitly check the given FileSystemResource.getPath() instead. I've revised this for 6.2.4.

This will be available in the upcoming 6.2.4 snapshot. Feel free to give it an early try!

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: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants