我正在尝试在我的网络应用程序中提供静态资源,并且我尝试过:
@SuppressWarnings("deprecation")
@Bean
WebMvcConfigurerAdapter configurer(){
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").
addResourceLocations("classpath:/static/");
}
};
}
但是 WebMvcConfigurerAdapter 在 Spring 5 中已被弃用。现在我如何访问静态资源?
Spring 5 - 静态资源
从文档中:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public", "classpath:/static/")
.setCachePeriod(31556926);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)