mowwwalker
mowwwalker

Reputation: 17334

Enforce case sensitivity in Spring resource resolution

We have a Spring Boot application where /css/StYLE.cSS will retrieve the css file located in static/css/style.css. Once packaged as a war and deployed to Tomcat, however, the urls become case sensitive and the include 404s.

Is there a way to enforce resource url case sensitivity in Spring MVC / Spring Boot?

It'd be easier to notice a case mismatch in development if the url 404's than by just being cautious.

Upvotes: 0

Views: 743

Answers (1)

Phil Webb
Phil Webb

Reputation: 8622

I assume that you're using an OS such as Windows where the filesystem is case-insensitive. In such cases, when you run during development, resources are served from the local folder on disk (which is case insensitive) but when you package up a JAR they are are served against the JAR zip file entries (which are case sensitive).

One option might be to plug in your own org.springframework.web.servlet.resource.PathResourceResolver and override getResource to make all resourcePath arguments lowercase. You'd then also need to enforce that all files under /static are lowercase (perhaps you could do this a build time). Alternatively, you might be able to check that the name of any found resource exactly matches the resourcePath to effectively make the filesystem version case-sensitive.

Upvotes: 2

Related Questions