Annotation Configuration Replacement for mvc:resources - Spring
For Spring 3 & 4:
One way to do this is to have your configuration class extend WebMvcConfigurerAdapter
, then override the following method as such:
@Overridepublic void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");}
Spring 5
As of Spring 5, the correct way to do this is to simply implement the WebMvcConfigurer interface.
For example:
@Configuration@EnableWebMvcpublic class MyApplication implements WebMvcConfigurer { public void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); }}
See deprecated message in: WebMvcConfigurerAdapter