user3578266
user3578266

Reputation:

Spring 4 Annotation based equivalent of static resource mapping

I just converted an XML configured Spring MVC project to being annotation based but I cannot seem to figure out what annotation to use (and where to place it) for static resource mappings. The mappings in my project's older XML based configuration were:

<mvc:resources mapping = "/css/**" location = "/css/"/> <mvc:resources mapping = "/images/**" location = "/images/"/> <mvc:resources mapping = "/*.html" location = "/"/>

Any help appreciated.

Upvotes: 3

Views: 4396

Answers (1)

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22506

@Configuration  
@EnableWebMvc  
public class WebAppConfig extends WebMvcConfigurerAdapter {  

        @Override  
        public void addResourceHandlers(ResourceHandlerRegistry registry) {  
                registry.addResourceHandler("/css/**").addResourceLocations("/css/");  
        }  
}

Upvotes: 4

Related Questions