WebMvcConfigurerAdapter#addResourceHandlers adds a resource handler for serving static resources based on the specified URL path patterns. ResourceHandlerRegistry stores the registration of resources.
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("/static/"); }
@EnableWebMvc @Configuration public class WebConfig implements WebMvcConfigurer {
@Override public void addViewControllers(ViewControllerRegistry registry) { //mapping url to a view ViewControllerRegistration r = registry.addViewController("/test"); r.setViewName("myView"); //setting status code r.setStatusCode(HttpStatus.GONE);
//mapping another url to a status code registry.addStatusController("/test2", HttpStatus.SERVICE_UNAVAILABLE); }
@Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.jsp("/WEB-INF/pages/", ".jsp"); } }