I have a default spring mvc application. In it, I have a controller like so:
@GetMapping("/**")
public String get(Model model) { }
Now this works for all requests, so that's fine, but it also works for static resources like js, img, css files.
How can I exclude these resources? I am using annotations btw..
What I have tried so far:
WebConfig:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
registry.addResourceHandler("/images/**").addResourceLocations("/images/");
registry.addResourceHandler("/css/**").addResourceLocations("/WEB-INF/css/");
registry.addResourceHandler("/js/**").addResourceLocations("/js/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
WebInitializer:
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{WebConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{WebConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
But it doesn't work, and the request for a css
file will be handled by the controller instead of showing me the static resource.
As I am not using Spring boot, the solutions mentioned in the linked question did not solve this for me.