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

查看:21
本文介绍了基于 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 = "/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天全站免登陆