Joh*_*des 7 java resources spring spring-mvc spring-webflux
我正在尝试在我的Web应用程序中提供静态资源,我试过:
@SuppressWarnings("deprecation")
@Bean
WebMvcConfigurerAdapter configurer(){
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").
addResourceLocations("classpath:/static/");
}
};
}
Run Code Online (Sandbox Code Playgroud)
但是在Spring 5中不推荐使用WebMvcConfigurerAdapter.如何立即访问静态资源?
alf*_*ope 10
从文档:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public", "classpath:/static/")
.setCachePeriod(31556926);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9980 次 |
| 最近记录: |