Spring 4 Annotation相当于静态资源映射

时间:2014-05-08 15:58:03

标签: spring static resources annotations

我刚刚将一个XML配置的Spring MVC项目转换为基于注释,但我似乎无法弄清楚要使用哪些注释(以及放置它)用于静态资源映射。我项目中基于XML的旧配置中的映射是:

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

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:4)

@Configuration  
@EnableWebMvc  
public class WebAppConfig extends WebMvcConfigurerAdapter {  

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