Deprecate rarely used bean definition variants
Closes gh-24875
This commit is contained in:
parent
6ea7ff1c6d
commit
d36407d585
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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}.
|
||||
*
|
||||
* <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.
|
||||
* i.e. typically in the XML file of the executing {@code DispatcherServlet}
|
||||
* or in a corresponding configuration class.
|
||||
*
|
||||
* <p>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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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`
|
||||
|
||||
|
|
|
@ -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.
|
||||
|===
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue