Java – spring 5 – how to provide static resources
•
Java
I'm trying to provide static resources in my web application. I've tried:
@SuppressWarnings("deprecation")
@Bean
WebMvcConfigurerAdapter configurer(){
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").
addResourceLocations("classpath:/static/");
}
};
}
However, webmvcconfigureradapter is not recommended in spring 5 How do I access static resources now?
Solution
Spring 5 – Static Resources
From document:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public","classpath:/static/")
.setCachePeriod(31556926);
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
