我正在尝试在我的Web应用程序中提供静态资源,我试过:
@SuppressWarnings("deprecation") @Bean WebMvcConfigurerAdapter configurer(){ return new WebMvcConfigurerAdapter() { @Override public void addResourceHandlers (ResourceHandlerRegistry registry) { registry.addResourceHandler("/**"). addResourceLocations("classpath:/static/"); } }; }
但是在Spring 5中不推荐使用WebMvcConfigurerAdapter.如何立即访问静态资源?
解决方法
Spring 5 – Static Resources
从文档:
@Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**") .addResourceLocations("/public","classpath:/static/") .setCachePeriod(31556926); } }