Saturday, 28 September 2013

Path aliasing for static resources in Spring dispatcher servlet

Path aliasing for static resources in Spring dispatcher servlet

I have a Spring Web app where the dispatcher servlet is only used for
static files. There also is a Jersey servlet for API calls from
JavaScript, mapped on another URL pattern, not too relevant to my problem.
At the moment my entire dispatcher configuration looks like this:
@Configuration
@EnableWebMvc
public class DispatcherConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/www/");
}
}
There is a main.html file right under www in my classpath. If a request
comes in for /main.html, the file is served correctly. Great.
Now, I would like this same file to be returned for requests on /, /part
and a bunch other paths. Basically, I want some kind of path aliasing
here, or direct mapping from path to file. How can I achieve it?

No comments:

Post a Comment