-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Peter Backlund opened SPR-3661 and commented
ViewResolvers that inherit UrlBasedViewResolver, such as FreemarkerVR and VelocityVR, don't have the ability to return null if a template file is not found. For example, FreemarkerView will run checkTemplate() on app context initialization, which will throw an IOException if the template file is not found. This exception will propagate past the view resover chaining in DispatcherServlet instead of sending the signal to try the next available view resolver.
My proposal is that the UrlBasedViewResolver.loadView() method catches whatever exception is thrown when the template file is missing (currently ApplicationContextException, might be a good idea to narrow down the scope by using a dedicated exception type), and instead return null (possibly with a flag to tune the behaviour).
Something like this:
protected View loadView(String viewName, Locale locale) throws Exception {
AbstractUrlBasedView view = buildView(viewName);
try {
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
} catch (TemplateNotFoundException e) {
if (throwExceptionIfNotFound) {
throw e;
} else {
return null;
}
}
}
Affects: 2.0.5