I am trying provide static resources in my web application and I tried:
@SuppressWarnings("deprecation")
@Bean
WebMvcConfigurerAdapter configurer(){
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").
addResourceLocations("classpath:/static/");
}
};
}
BUT WebMvcConfigurerAdapter is deprecated in Spring 5. How can I access the static resources now?
Spring 5 - Static Resources
From the documentation:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public", "classpath:/static/")
.setCachePeriod(31556926);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With