我刚刚将 XML 配置的 Spring MVC 项目转换为基于注释的项目,但我似乎无法弄清楚静态资源映射要使用什么注释(以及将其放置在何处)。我的项目旧的基于 XML 的配置中的映射是:
<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 基于注解的静态资源映射等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23546791/