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

@ -74,7 +74,10 @@ import org.springframework.util.StringUtils;
* @author Rob Harrop * @author Rob Harrop
* @since 26.11.2003 * @since 26.11.2003
* @see DefaultListableBeanFactory * @see DefaultListableBeanFactory
* @deprecated as of 5.3, in favor of Spring's common bean definition formats
* and/or custom reader implementations
*/ */
@Deprecated
public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader { public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader {
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.util.Properties;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -42,10 +41,13 @@ import org.springframework.util.Assert;
* @author Juergen Hoeller * @author Juergen Hoeller
* @see #loadBeanDefinitions * @see #loadBeanDefinitions
* @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader * @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader
* @deprecated as of 5.3, in favor of Spring's common bean definition formats
* and/or custom reader implementations
*/ */
@Deprecated
public class JdbcBeanDefinitionReader { public class JdbcBeanDefinitionReader {
private final PropertiesBeanDefinitionReader propReader; private final org.springframework.beans.factory.support.PropertiesBeanDefinitionReader propReader;
@Nullable @Nullable
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@ -59,7 +61,7 @@ public class JdbcBeanDefinitionReader {
* @see #setJdbcTemplate * @see #setJdbcTemplate
*/ */
public JdbcBeanDefinitionReader(BeanDefinitionRegistry beanFactory) { public JdbcBeanDefinitionReader(BeanDefinitionRegistry beanFactory) {
this.propReader = new PropertiesBeanDefinitionReader(beanFactory); this.propReader = new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(beanFactory);
} }
/** /**
@ -69,9 +71,9 @@ public class JdbcBeanDefinitionReader {
* @see #setDataSource * @see #setDataSource
* @see #setJdbcTemplate * @see #setJdbcTemplate
*/ */
public JdbcBeanDefinitionReader(PropertiesBeanDefinitionReader beanDefinitionReader) { public JdbcBeanDefinitionReader(org.springframework.beans.factory.support.PropertiesBeanDefinitionReader reader) {
Assert.notNull(beanDefinitionReader, "Bean definition reader must not be null"); Assert.notNull(reader, "Bean definition reader must not be null");
this.propReader = beanDefinitionReader; this.propReader = reader;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.test.context.support;
import java.util.Properties; import java.util.Properties;
import org.springframework.beans.factory.support.BeanDefinitionReader; import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -30,17 +29,20 @@ import org.springframework.util.ObjectUtils;
* *
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
* @deprecated as of 5.3, in favor of Spring's common bean definition formats
* and/or custom loader implementations
*/ */
@Deprecated
public class GenericPropertiesContextLoader extends AbstractGenericContextLoader { public class GenericPropertiesContextLoader extends AbstractGenericContextLoader {
/** /**
* Creates a new {@link PropertiesBeanDefinitionReader}. * Creates a new {@link org.springframework.beans.factory.support.PropertiesBeanDefinitionReader}.
* @return a new PropertiesBeanDefinitionReader * @return a new PropertiesBeanDefinitionReader
* @see PropertiesBeanDefinitionReader * @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader
*/ */
@Override @Override
protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) { protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) {
return new PropertiesBeanDefinitionReader(context); return new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(context);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,8 +32,8 @@ import org.springframework.lang.Nullable;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @see org.springframework.web.servlet.view.InternalResourceViewResolver * @see org.springframework.web.servlet.view.InternalResourceViewResolver
* @see org.springframework.web.servlet.view.ResourceBundleViewResolver * @see org.springframework.web.servlet.view.ContentNegotiatingViewResolver
* @see org.springframework.web.servlet.view.XmlViewResolver * @see org.springframework.web.servlet.view.BeanNameViewResolver
*/ */
public interface ViewResolver { public interface ViewResolver {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,16 +29,8 @@ import org.springframework.web.servlet.ViewResolver;
/** /**
* A simple implementation of {@link org.springframework.web.servlet.ViewResolver} * A simple implementation of {@link org.springframework.web.servlet.ViewResolver}
* that interprets a view name as a bean name in the current application context, * that interprets a view name as a bean name in the current application context,
* i.e. typically in the XML file of the executing {@code DispatcherServlet}. * i.e. typically in the XML file of the executing {@code DispatcherServlet}
* * or in a corresponding configuration class.
* <p>This resolver can be handy for small applications, keeping all definitions
* ranging from controllers to views in the same place. For larger applications,
* {@link XmlViewResolver} will be the better choice, as it separates the XML
* view bean definitions into a dedicated views file.
*
* <p>Note: Neither this {@code ViewResolver} nor {@link XmlViewResolver} supports
* internationalization. Consider {@link ResourceBundleViewResolver} if you need
* to apply different view resources per locale.
* *
* <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface * <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface
* in order to allow for flexible participation in {@code ViewResolver} chaining. * in order to allow for flexible participation in {@code ViewResolver} chaining.
@ -48,8 +40,6 @@ import org.springframework.web.servlet.ViewResolver;
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 18.06.2003 * @since 18.06.2003
* @see XmlViewResolver
* @see ResourceBundleViewResolver
* @see UrlBasedViewResolver * @see UrlBasedViewResolver
*/ */
public class BeanNameViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered { public class BeanNameViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -59,7 +58,11 @@ import org.springframework.web.servlet.View;
* @see java.util.ResourceBundle#getBundle * @see java.util.ResourceBundle#getBundle
* @see java.util.PropertyResourceBundle * @see java.util.PropertyResourceBundle
* @see UrlBasedViewResolver * @see UrlBasedViewResolver
* @see BeanNameViewResolver
* @deprecated as of 5.3, in favor of Spring's common view resolver variants
* and/or custom resolver implementations
*/ */
@Deprecated
public class ResourceBundleViewResolver extends AbstractCachingViewResolver public class ResourceBundleViewResolver extends AbstractCachingViewResolver
implements Ordered, InitializingBean, DisposableBean { implements Ordered, InitializingBean, DisposableBean {
@ -249,7 +252,8 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver
factory.setServletContext(getServletContext()); factory.setServletContext(getServletContext());
// Load bean definitions from resource bundle. // Load bean definitions from resource bundle.
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(factory); org.springframework.beans.factory.support.PropertiesBeanDefinitionReader reader =
new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(factory);
reader.setDefaultParentBean(this.defaultParentView); reader.setDefaultParentBean(this.defaultParentView);
for (ResourceBundle bundle : bundles) { for (ResourceBundle bundle : bundles) {
reader.registerBeanDefinitions(bundle); reader.registerBeanDefinitions(bundle);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -52,9 +52,12 @@ import org.springframework.web.servlet.View;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 18.06.2003 * @since 18.06.2003
* @see org.springframework.context.ApplicationContext#getResource * @see org.springframework.context.ApplicationContext#getResource
* @see ResourceBundleViewResolver
* @see UrlBasedViewResolver * @see UrlBasedViewResolver
* @see BeanNameViewResolver
* @deprecated as of 5.3, in favor of Spring's common view resolver variants
* and/or custom resolver implementations
*/ */
@Deprecated
public class XmlViewResolver extends AbstractCachingViewResolver public class XmlViewResolver extends AbstractCachingViewResolver
implements Ordered, InitializingBean, DisposableBean { implements Ordered, InitializingBean, DisposableBean {

View File

@ -2307,8 +2307,6 @@ Spring provides the following implementations:
locations. locations.
* `GenericXmlWebContextLoader`: Loads a `WebApplicationContext` from XML resource * `GenericXmlWebContextLoader`: Loads a `WebApplicationContext` from XML resource
locations. locations.
* `GenericPropertiesContextLoader`: Loads a standard `ApplicationContext` from Java
properties files.
[[testcontext-bootstrapping]] [[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]] [[mvc-view-jsp-resolver]]
=== View Resolvers === View Resolvers
When developing with JSPs, you can declare a `InternalResourceViewResolver` or a When developing with JSPs, you typically declare a `InternalResourceViewResolver` bean.
`ResourceBundleViewResolver` bean.
`ResourceBundleViewResolver` relies on a properties file to define the view names `InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in
mapped to a class and a URL. With a `ResourceBundleViewResolver`, you can mix particular for JSPs. As a best practice, we strongly encourage placing your JSP files in
different types of views by using only one resolver, as the following example shows: a directory under the `'WEB-INF'` directory so there can be no direct access by clients.
[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.
[source,xml,indent=0,subs="verbatim,quotes"] [source,xml,indent=0,subs="verbatim,quotes"]
---- ----
@ -1714,13 +1694,12 @@ The following example `ApplicationContext` configuration shows how to do so:
</bean> </bean>
---- ----
The preceding example defines five files that contain definitions. The files are all located in The preceding example defines five files that contain definitions. The files are all
the `WEB-INF/defs` directory. At initialization of the `WebApplicationContext`, the located in the `WEB-INF/defs` directory. At initialization of the `WebApplicationContext`,
files are loaded, and the definitions factory are initialized. After that has 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 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` 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 as with any other view technology in Spring : typically a convenient `TilesViewResolver`.
implementations, the `UrlBasedViewResolver` and the `ResourceBundleViewResolver`.
You can specify locale-specific Tiles definitions by adding an underscore and then You can specify locale-specific Tiles definitions by adding an underscore and then
the locale, as the following example shows: 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]] [[mvc-view-tiles-preparer]]
==== `SimpleSpringPreparerFactory` and `SpringBeanPreparerFactory` ==== `SimpleSpringPreparerFactory` and `SpringBeanPreparerFactory`

View File

@ -736,23 +736,11 @@ The following table provides more details on the `ViewResolver` hierarchy:
| ViewResolver| Description | ViewResolver| Description
| `AbstractCachingViewResolver` | `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 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 cache by setting the `cache` property to `false`. Furthermore, if you must refresh
certain view at runtime (for example, when a FreeMarker template is modified), you can use a certain view at runtime (for example, when a FreeMarker template is modified),
the `removeFromCache(String viewName, Locale loc)` method. 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>>.
| `UrlBasedViewResolver` | `UrlBasedViewResolver`
| Simple implementation of the `ViewResolver` interface that affects the direct | 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` | `ContentNegotiatingViewResolver`
| Implementation of the `ViewResolver` interface that resolves a view based on the | Implementation of the `ViewResolver` interface that resolves a view based on the
request file name or `Accept` header. See <<mvc-multiple-representations>>. 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.
|=== |===