From d36407d5852b7a90eae28b1025f142f739a9c9bb Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 17 Jun 2020 10:59:55 +0200 Subject: [PATCH] Deprecate rarely used bean definition variants Closes gh-24875 --- .../PropertiesBeanDefinitionReader.java | 3 + .../support/JdbcBeanDefinitionReader.java | 16 +++-- .../GenericPropertiesContextLoader.java | 12 ++-- .../web/servlet/ViewResolver.java | 6 +- .../servlet/view/BeanNameViewResolver.java | 16 +---- .../view/ResourceBundleViewResolver.java | 10 ++- .../web/servlet/view/XmlViewResolver.java | 7 +- src/docs/asciidoc/testing.adoc | 2 - src/docs/asciidoc/web/webmvc-view.adoc | 72 +++---------------- src/docs/asciidoc/web/webmvc.adoc | 26 +++---- 10 files changed, 55 insertions(+), 115 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java index 4d24c57e86..81c06aca4c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java @@ -74,7 +74,10 @@ import org.springframework.util.StringUtils; * @author Rob Harrop * @since 26.11.2003 * @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 { /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java index 9791bd4b52..d266c35ad7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java @@ -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"); * 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 org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -42,10 +41,13 @@ import org.springframework.util.Assert; * @author Juergen Hoeller * @see #loadBeanDefinitions * @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 { - private final PropertiesBeanDefinitionReader propReader; + private final org.springframework.beans.factory.support.PropertiesBeanDefinitionReader propReader; @Nullable private JdbcTemplate jdbcTemplate; @@ -59,7 +61,7 @@ public class JdbcBeanDefinitionReader { * @see #setJdbcTemplate */ 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 #setJdbcTemplate */ - public JdbcBeanDefinitionReader(PropertiesBeanDefinitionReader beanDefinitionReader) { - Assert.notNull(beanDefinitionReader, "Bean definition reader must not be null"); - this.propReader = beanDefinitionReader; + public JdbcBeanDefinitionReader(org.springframework.beans.factory.support.PropertiesBeanDefinitionReader reader) { + Assert.notNull(reader, "Bean definition reader must not be null"); + this.propReader = reader; } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java index efc2a358e5..66f1f8e9e3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/GenericPropertiesContextLoader.java @@ -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"); * 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 org.springframework.beans.factory.support.BeanDefinitionReader; -import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.util.ObjectUtils; @@ -30,17 +29,20 @@ import org.springframework.util.ObjectUtils; * * @author Sam Brannen * @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 { /** - * Creates a new {@link PropertiesBeanDefinitionReader}. + * Creates a new {@link org.springframework.beans.factory.support.PropertiesBeanDefinitionReader}. * @return a new PropertiesBeanDefinitionReader - * @see PropertiesBeanDefinitionReader + * @see org.springframework.beans.factory.support.PropertiesBeanDefinitionReader */ @Override protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) { - return new PropertiesBeanDefinitionReader(context); + return new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(context); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java index 8a35e2e9d6..4f797a2523 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ViewResolver.java @@ -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"); * 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 Juergen Hoeller * @see org.springframework.web.servlet.view.InternalResourceViewResolver - * @see org.springframework.web.servlet.view.ResourceBundleViewResolver - * @see org.springframework.web.servlet.view.XmlViewResolver + * @see org.springframework.web.servlet.view.ContentNegotiatingViewResolver + * @see org.springframework.web.servlet.view.BeanNameViewResolver */ public interface ViewResolver { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/BeanNameViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/BeanNameViewResolver.java index 988909b6c1..577b267d88 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/BeanNameViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/BeanNameViewResolver.java @@ -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"); * 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} * 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}. - * - *

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. - * - *

Note: Neither this {@code ViewResolver} nor {@link XmlViewResolver} supports - * internationalization. Consider {@link ResourceBundleViewResolver} if you need - * to apply different view resources per locale. + * i.e. typically in the XML file of the executing {@code DispatcherServlet} + * or in a corresponding configuration class. * *

Note: This {@code ViewResolver} implements the {@link Ordered} interface * in order to allow for flexible participation in {@code ViewResolver} chaining. @@ -48,8 +40,6 @@ import org.springframework.web.servlet.ViewResolver; * * @author Juergen Hoeller * @since 18.06.2003 - * @see XmlViewResolver - * @see ResourceBundleViewResolver * @see UrlBasedViewResolver */ public class BeanNameViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java index a2f8dda6b9..040c0bfcbd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java @@ -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"); * 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.InitializingBean; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.Ordered; import org.springframework.lang.Nullable; @@ -59,7 +58,11 @@ import org.springframework.web.servlet.View; * @see java.util.ResourceBundle#getBundle * @see java.util.PropertyResourceBundle * @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 implements Ordered, InitializingBean, DisposableBean { @@ -249,7 +252,8 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver factory.setServletContext(getServletContext()); // 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); for (ResourceBundle bundle : bundles) { reader.registerBeanDefinitions(bundle); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java index 0f3e75c813..2167badac6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java @@ -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"); * 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 * @since 18.06.2003 * @see org.springframework.context.ApplicationContext#getResource - * @see ResourceBundleViewResolver * @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 implements Ordered, InitializingBean, DisposableBean { diff --git a/src/docs/asciidoc/testing.adoc b/src/docs/asciidoc/testing.adoc index ad7a7b63e6..1f184add55 100644 --- a/src/docs/asciidoc/testing.adoc +++ b/src/docs/asciidoc/testing.adoc @@ -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]] diff --git a/src/docs/asciidoc/web/webmvc-view.adoc b/src/docs/asciidoc/web/webmvc-view.adoc index 73b61e8f11..cc476fa7b9 100644 --- a/src/docs/asciidoc/web/webmvc-view.adoc +++ b/src/docs/asciidoc/web/webmvc-view.adoc @@ -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"] ----- - - - - - - # 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: ---- -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"] ----- - - - ----- - -[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` diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 4a7228941f..747b9eb048 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -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 - <>. + 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 <>. + +| `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. |===