Replacing annotation configuration for mvc: resources - Spring

I am trying to update spring mvc project to use new annotations and get rid of my xml. I used to upload my static resources to my web.xml using the line:

 <mvc:resources mapping="/resources/**" location="/resources/" /> 

Now I use the annotation WebApplicationInitializer and @EnableWebMvc to start my service without any xml files, but I cannot figure out how to load my resources.

Is there an annotation or a new configuration to return these resources without using xml?

+56
java spring spring-mvc configuration
Feb 13 '13 at 19:45
source share
1 answer

One way to do this is to extend the WebMvcConfigurerAdapter configuration WebMvcConfigurerAdapter , and then override the following method as such:

 @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); } 
+98
Feb 13 '13 at 20:42
source share



All Articles