Fix exception if no RequestDataValueProcessor is present

This modification fixes the way AbstractView retrieves the
RequestDataValueProcessor bean, correctly returning null if there
is no bean of such type at the Application Context.

This avoids an exception in RedirectView (which extends AbstractView)
when trying to post-process the URL generated for redirection, when
no RequestDataValueProcessor exists.

Issue: SPR-15136
This commit is contained in:
Daniel Fernández
2017-01-14 00:00:41 +01:00
committed by Rossen Stoyanchev
parent 052014783a
commit 8b7f3a65ed

View File

@@ -191,11 +191,12 @@ public abstract class AbstractView implements View, ApplicationContextAware {
* <p>The default implementation looks in the {@link #getApplicationContext()
* Spring configuration} for a {@code RequestDataValueProcessor} bean with
* the name {@link #REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME}.
* @return the RequestDataValueProcessor, or null if there is none at the application context.
*/
protected RequestDataValueProcessor getRequestDataValueProcessor() {
if (getApplicationContext() != null) {
String beanName = REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME;
return getApplicationContext().getBean(beanName, RequestDataValueProcessor.class);
ApplicationContext context = getApplicationContext();
if (context != null && context.containsBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
return context.getBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
}
return null;
}