0

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

sanluck
  • 1,544
  • 1
  • 12
  • 22
user2035693
  • 193
  • 2
  • 16

2 Answers2

1

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.

Rob Baily
  • 2,770
  • 17
  • 26
  • when I write `` that's also a path on the server, but not a visible path by spring-boot or thymeleaf. So, to understand, because is not a visible path is not being handled? – user2035693 Mar 23 '16 at 20:57
  • That path is being resolved on the browser so the server never sees the .. references so it can't be used in a path matching pattern. – Rob Baily Mar 23 '16 at 21:50
1

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?

Community
  • 1
  • 1
sanluck
  • 1,544
  • 1
  • 12
  • 22
  • thank you. This indeed works for the live server, but for dev and testing I kind of gave up on this idea since I don't have access to resources locally and the only way to access them are through http. I'm trying to solve it with `ResourceResolver` by modifying the path with an url. Unfortunately is prepanding the path from matched resource handler (`/../../css/http://website.com/assets/`) and I don't see a way to remove it from `ResourceResolver`. I keep looking what I have to override for that – user2035693 Mar 25 '16 at 10:02
  • So if your resources placed in the external resource, why you didn't created something like `CDN` for this resources? Create separate project with static resources and reference on it. – sanluck Mar 25 '16 at 10:39
  • unfortunately I have no access to that server to do what I want – user2035693 Mar 25 '16 at 10:53