Deprecate rarely used bean definition variants

Closes gh-24875
This commit is contained in:
Juergen Hoeller
2020-06-17 10:59:55 +02:00
parent 6ea7ff1c6d
commit d36407d585
10 changed files with 55 additions and 115 deletions

View File

@@ -2307,8 +2307,6 @@ Spring provides the following implementations:
locations.
* `GenericXmlWebContextLoader`: Loads a `WebApplicationContext` from XML resource
locations.
* `GenericPropertiesContextLoader`: Loads a standard `ApplicationContext` from Java
properties files.
[[testcontext-bootstrapping]]

View File

@@ -840,31 +840,11 @@ The Spring Framework has a built-in integration for using Spring MVC with JSP an
[[mvc-view-jsp-resolver]]
=== View Resolvers
When developing with JSPs, you can declare a `InternalResourceViewResolver` or a
`ResourceBundleViewResolver` bean.
When developing with JSPs, you typically declare a `InternalResourceViewResolver` bean.
`ResourceBundleViewResolver` relies on a properties file to define the view names
mapped to a class and a URL. With a `ResourceBundleViewResolver`, you can mix
different types of views by using only one resolver, as the following example shows:
[source,xml,indent=0,subs="verbatim,quotes"]
----
<!-- the ResourceBundleViewResolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views"/>
</bean>
# And a sample properties file is used (views.properties in WEB-INF/classes):
welcome.(class)=org.springframework.web.servlet.view.JstlView
welcome.url=/WEB-INF/jsp/welcome.jsp
productList.(class)=org.springframework.web.servlet.view.JstlView
productList.url=/WEB-INF/jsp/productlist.jsp
----
`InternalResourceViewResolver` can also be used for JSPs. As a best practice, we strongly
encourage placing your JSP files in a directory under the `'WEB-INF'` directory so there
can be no direct access by clients.
`InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in
particular for JSPs. As a best practice, we strongly encourage placing your JSP files in
a directory under the `'WEB-INF'` directory so there can be no direct access by clients.
[source,xml,indent=0,subs="verbatim,quotes"]
----
@@ -1714,13 +1694,12 @@ The following example `ApplicationContext` configuration shows how to do so:
</bean>
----
The preceding example defines five files that contain definitions. The files are all located in
the `WEB-INF/defs` directory. At initialization of the `WebApplicationContext`, the
files are loaded, and the definitions factory are initialized. After that has
The preceding example defines five files that contain definitions. The files are all
located in the `WEB-INF/defs` directory. At initialization of the `WebApplicationContext`,
the files are loaded, and the definitions factory are initialized. After that has
been done, the Tiles included in the definition files can be used as views within your
Spring web application. To be able to use the views, you have to have a `ViewResolver`
as with any other view technology used with Spring. You can use either of two
implementations, the `UrlBasedViewResolver` and the `ResourceBundleViewResolver`.
as with any other view technology in Spring : typically a convenient `TilesViewResolver`.
You can specify locale-specific Tiles definitions by adding an underscore and then
the locale, as the following example shows:
@@ -1759,41 +1738,6 @@ resolve. The following bean defines a `UrlBasedViewResolver`:
----
[[mvc-view-tiles-resource]]
==== `ResourceBundleViewResolver`
The `ResourceBundleViewResolver` has to be provided with a property file that contains
view names and view classes that the resolver can use. The following example shows a bean
definition for a `ResourceBundleViewResolver` and the corresponding view names and view
classes (taken from the Pet Clinic sample):
[source,xml,indent=0,subs="verbatim,quotes"]
----
<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views"/>
</bean>
----
[literal,subs="verbatim,quotes"]
----
...
welcomeView.(class)=org.springframework.web.servlet.view.tiles3.TilesView
welcomeView.url=welcome (this is the name of a Tiles definition)
vetsView.(class)=org.springframework.web.servlet.view.tiles3.TilesView
vetsView.url=vetsView (again, this is the name of a Tiles definition)
findOwnersForm.(class)=org.springframework.web.servlet.view.JstlView
findOwnersForm.url=/WEB-INF/jsp/findOwners.jsp
...
----
When you use the `ResourceBundleViewResolver`, you can easily mix
different view technologies.
Note that the `TilesView` class supports JSTL (the JSP Standard Tag Library).
[[mvc-view-tiles-preparer]]
==== `SimpleSpringPreparerFactory` and `SpringBeanPreparerFactory`

View File

@@ -736,23 +736,11 @@ The following table provides more details on the `ViewResolver` hierarchy:
| ViewResolver| Description
| `AbstractCachingViewResolver`
| Sub-classes of `AbstractCachingViewResolver` cache view instances that they resolve.
| Subclasses of `AbstractCachingViewResolver` cache view instances that they resolve.
Caching improves performance of certain view technologies. You can turn off the
cache by setting the `cache` property to `false`. Furthermore, if you must refresh a
certain view at runtime (for example, when a FreeMarker template is modified), you can use
the `removeFromCache(String viewName, Locale loc)` method.
| `XmlViewResolver`
| Implementation of `ViewResolver` that accepts a configuration file written in XML with
the same DTD as Spring's XML bean factories. The default configuration file is
`/WEB-INF/views.xml`.
| `ResourceBundleViewResolver`
| Implementation of `ViewResolver` that uses bean definitions in a `ResourceBundle`,
specified by the bundle base name. For each view it is supposed to resolve, it uses
the value of the property `[viewname].(class)` as the view class and the value of the
property `[viewname].url` as the view URL. You can find examples in the chapter on
<<mvc-view>>.
cache by setting the `cache` property to `false`. Furthermore, if you must refresh
a certain view at runtime (for example, when a FreeMarker template is modified),
you can use the `removeFromCache(String viewName, Locale loc)` method.
| `UrlBasedViewResolver`
| Simple implementation of the `ViewResolver` interface that affects the direct
@@ -774,6 +762,12 @@ The following table provides more details on the `ViewResolver` hierarchy:
| `ContentNegotiatingViewResolver`
| Implementation of the `ViewResolver` interface that resolves a view based on the
request file name or `Accept` header. See <<mvc-multiple-representations>>.
| `BeanNameViewResolver`
| Implementation of the `ViewResolver` interface that interprets a view name as a
bean name in the current application context. This is a very flexible variant which
allows for mixing and matching different view types based on distinct view names.
Each such `View` can be defined as a bean e.g. in XML or in configuration classes.
|===