Spring 4 Annotation based equivalent of static resource mapping

Deadly 提交于 2019-12-22 09:46:49

问题


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.


回答1:


@Configuration  
@EnableWebMvc  
public class WebAppConfig extends WebMvcConfigurerAdapter {  

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


来源:https://stackoverflow.com/questions/23546791/spring-4-annotation-based-equivalent-of-static-resource-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!