lundi 6 avril 2015

Recommended way to serve static resources in Spring

I am creating a simple Spring application. What is reasonable approach to serving static resources? I have used this type of code:



public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.
addResourceHandler("/resources/**").
addResourceLocations("/resources/");


But it doesn't do anything. I get 405 errors for anything that's under the /resources directory.


Should I write a Servlet Filter to intercept these requests before they get to Spring's DispatcherServlet? Or is there some other way to do this? I would prefer to not have to do something strange like running two web servers, or creating a @RequestMapping for every static resources on my site or something like that.


Aucun commentaire:

Enregistrer un commentaire