if you don't register any viewcontrollers, you might get a null here:
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#viewControllerHandlerMapping
@Bean
@Nullable
public HandlerMapping viewControllerHandlerMapping() {
ViewControllerRegistry registry = new ViewControllerRegistry(this.applicationContext);
addViewControllers(registry);
AbstractHandlerMapping handlerMapping = registry.buildHandlerMapping();
if (handlerMapping == null) {
return null;
}
handlerMapping.setPathMatcher(mvcPathMatcher());
handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
handlerMapping.setInterceptors(getInterceptors());
handlerMapping.setCorsConfigurations(getCorsConfigurations());
return handlerMapping;
}
but when we iterate over a handlerMappings , 'mapping ' might be null: org.springframework.web.servlet.DispatcherServlet#getHandler
@Nullable
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
if (this.handlerMappings != null) {
for (HandlerMapping mapping : this.handlerMappings) {
HandlerExecutionChain handler = mapping.getHandler(request);
if (handler != null) {
return handler;
}
}
}
return null;
}
so I'm going to get an exception.
Comment From: rstoyanchev
I can't reproduce it this. It shouldn't be possible and if it was, it would have been reported long ago. If you actually have this issue please provide a sample to demonstrate it.