1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
26
26
import org .springframework .web .servlet .ViewResolver ;
27
27
28
28
/**
29
- * Simple implementation of ViewResolver that interprets a view name
30
- * as bean name in the current application context, i.e. in the XML
31
- * file of the executing DispatcherServlet.
29
+ * A simple implementation of {@link org.springframework.web.servlet.ViewResolver}
30
+ * that interprets a view name as a bean name in the current application context,
31
+ * i.e. typically in the XML file of the executing {@code DispatcherServlet} .
32
32
*
33
- * <p>This resolver can be handy for small applications, keeping all
34
- * definitions ranging from controllers to views in the same place.
35
- * For normal applications, XmlViewResolver will be the better choice, as
36
- * it separates the XML view bean definitions into a dedicated views file.
37
- * View beans should virtually never have references to any other
38
- * application beans - such a separation will make this clear.
33
+ * <p>This resolver can be handy for small applications, keeping all definitions
34
+ * ranging from controllers to views in the same place. For larger applications,
35
+ * {@link XmlViewResolver} will be the better choice, as it separates the XML
36
+ * view bean definitions into a dedicated views file.
39
37
*
40
- * <p>This ViewResolver does not support internationalization.
41
- * Consider ResourceBundleViewResolver if you need to apply different
42
- * view resources per locale.
38
+ * <p>Note: Neither this {@code ViewResolver} nor {@link XmlViewResolver} supports
39
+ * internationalization. Consider {@link ResourceBundleViewResolver} if you need
40
+ * to apply different view resources per locale.
43
41
*
44
- * <p>Note: This ViewResolver implements the Ordered interface to allow for
45
- * flexible participation in ViewResolver chaining. For example, some special
46
- * views could be defined via this ViewResolver (giving it 0 as "order" value),
47
- * while all remaining views could be resolved by a UrlBasedViewResolver.
42
+ * <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface
43
+ * in order to allow for flexible participation in {@code ViewResolver} chaining.
44
+ * For example, some special views could be defined via this {@code ViewResolver}
45
+ * (giving it 0 as "order" value), while all remaining views could be resolved by
46
+ * a {@link UrlBasedViewResolver}.
48
47
*
49
48
* @author Juergen Hoeller
50
49
* @since 18.06.2003
@@ -63,15 +62,27 @@ public void setOrder(int order) {
63
62
64
63
@ Override
65
64
public int getOrder () {
66
- return order ;
65
+ return this . order ;
67
66
}
68
67
69
68
70
69
@ Override
71
70
public View resolveViewName (String viewName , Locale locale ) throws BeansException {
72
71
ApplicationContext context = getApplicationContext ();
73
72
if (!context .containsBean (viewName )) {
74
- // Allow for ViewResolver chaining.
73
+ if (logger .isDebugEnabled ()) {
74
+ logger .debug ("No matching bean found for view name '" + viewName + "'" );
75
+ }
76
+ // Allow for ViewResolver chaining...
77
+ return null ;
78
+ }
79
+ if (!context .isTypeMatch (viewName , View .class )) {
80
+ if (logger .isDebugEnabled ()) {
81
+ logger .debug ("Found matching bean for view name '" + viewName +
82
+ "' - to be ignored since it does not implement View" );
83
+ }
84
+ // Since we're looking into the general ApplicationContext here,
85
+ // let's accept this as a non-match and allow for chaining as well...
75
86
return null ;
76
87
}
77
88
return context .getBean (viewName , View .class );
0 commit comments