user2035693
user2035693

Reputation: 313

spring Resource handler not handling /../**

I'm using spring boot with thymeleaf and all my resources are outside spring application on a path like "/../../css/main.css". On dev env should resolve the path using an url and live env go on the path.

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String templates=env.getProperty("spring.thymeleaf.prefix");
    registry.addResourceHandler("/../../css/**")
            .addResourceLocations(templates);
}
// spring.thymeleaf.prefix = http://website.com/assets/

Why the resource handler is not handling these kind of resources, but if I "/**" is handling without problems? Am I missing something?

Edit: if resourceHandler is "/css/**" and location is an url is not being handled either

Upvotes: 0

Views: 1033

Answers (2)

sanluck
sanluck

Reputation: 1554

You can't reference to external resources as you want cause resolver looking for resources from classpath.

Try to do it like in this issue - Add external resources folder to Spring Boot or in this - How do I use Spring Boot to serve static content located in Dropbox folder?

Upvotes: 1

Rob Baily
Rob Baily

Reputation: 3019

I am pretty sure that using .. in the addResourceHandler is not valid but I do not have specific documentation to back it up. The path is describing a pattern that the server gets not what is listed in the browser. From the function doc: "based on the specified URL path patterns". If you reference .. from a browser that will still be changed to some absolute path to be sent to the server. This is why your other versions work without issue.

Upvotes: 1

Related Questions