基于Spring 4 Annotation的静态资源映射等效项 [英] Spring 4 Annotation based equivalent of static resource mapping

查看:66
本文介绍了基于Spring 4 Annotation的静态资源映射等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将配置了XML的Spring MVC项目转换为基于注释,但是我似乎无法弄清楚要用于静态资源映射的注释(以及放置在何处).在我的项目的较旧的基于XML的配置中,映射为:

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 = "/"/>

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

任何帮助表示赞赏.

推荐答案

@Configuration  
@EnableWebMvc  
public class WebAppConfig extends WebMvcConfigurerAdapter {  

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

这篇关于基于Spring 4 Annotation的静态资源映射等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆