Skip to content

Commit 0b617a8

Browse files
committed
Deprecate PreferencesPlaceholderConfigurer along with its base class
Also removing common PropertyPlaceholderConfigurer doc references. See gh-22181
1 parent d257833 commit 0b617a8

File tree

9 files changed

+53
-66
lines changed

9 files changed

+53
-66
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@
2727
* concrete implementations.
2828
*
2929
* <p>This is just a minimal interface: The main intention is to allow a
30-
* {@link BeanFactoryPostProcessor} such as {@link PropertyPlaceholderConfigurer}
31-
* to introspect and modify property values and other bean metadata.
30+
* {@link BeanFactoryPostProcessor} to introspect and modify property values
31+
* and other bean metadata.
3232
*
3333
* @author Juergen Hoeller
3434
* @author Rob Harrop

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
* the property values and constructor argument values contained in them,
3535
* resolving bean metadata values.
3636
*
37-
* <p>Used by {@link PropertyPlaceholderConfigurer} to parse all String values
37+
* <p>Used by {@link PlaceholderConfigurerSupport} to parse all String values
3838
* contained in a BeanDefinition, resolving any placeholders found.
3939
*
4040
* @author Juergen Hoeller
@@ -43,7 +43,7 @@
4343
* @see BeanDefinition
4444
* @see BeanDefinition#getPropertyValues
4545
* @see BeanDefinition#getConstructorArgumentValues
46-
* @see PropertyPlaceholderConfigurer
46+
* @see PlaceholderConfigurerSupport
4747
*/
4848
public class BeanDefinitionVisitor {
4949

spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -484,7 +484,6 @@ public ValueHolder(@Nullable Object value, @Nullable String type, @Nullable Stri
484484

485485
/**
486486
* Set the value for the constructor argument.
487-
* @see PropertyPlaceholderConfigurer
488487
*/
489488
public void setValue(@Nullable Object value) {
490489
this.value = value;

spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,9 @@
4242
* @see #setSystemTreePath
4343
* @see #setUserTreePath
4444
* @see java.util.prefs.Preferences
45+
* @deprecated as of 5.2, along with {@link PropertyPlaceholderConfigurer}
4546
*/
47+
@Deprecated
4648
public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements InitializingBean {
4749

4850
@Nullable

spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@
4949
* @see #setSystemPropertiesModeName
5050
* @see PlaceholderConfigurerSupport
5151
* @see PropertyOverrideConfigurer
52-
53-
* @deprecated use {@code org.springframework.context.support.PropertySourcesPlaceholderConfigurer} instead;
54-
* it is more flexible through taking advantage of the {@link org.springframework.core.env.Environment} and
55-
* {@link org.springframework.core.env.PropertySource} mechanisms.
52+
* @deprecated as of 5.2; use {@code org.springframework.context.support.PropertySourcesPlaceholderConfigurer}
53+
* instead which is more flexible through taking advantage of the {@link org.springframework.core.env.Environment}
54+
* and {@link org.springframework.core.env.PropertySource} mechanisms.
5655
*/
5756
@Deprecated
5857
public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport {

spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,7 +87,6 @@ public TypedStringValue(@Nullable String value, String targetTypeName) {
8787
* Set the String value.
8888
* <p>Only necessary for manipulating a registered value,
8989
* for example in BeanFactoryPostProcessors.
90-
* @see PropertyPlaceholderConfigurer
9190
*/
9291
public void setValue(@Nullable String value) {
9392
this.value = value;
@@ -105,7 +104,6 @@ public String getValue() {
105104
* Set the type to convert to.
106105
* <p>Only necessary for manipulating a registered value,
107106
* for example in BeanFactoryPostProcessors.
108-
* @see PropertyPlaceholderConfigurer
109107
*/
110108
public void setTargetType(Class<?> targetType) {
111109
Assert.notNull(targetType, "'targetType' must not be null");

spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@ protected Class<?> getBeanClass(Element element) {
5151

5252
// The user has explicitly specified a value for system-properties-mode: revert to
5353
// PropertyPlaceholderConfigurer to ensure backward compatibility with 3.0 and earlier.
54+
// This is deprecated; to be removed along with PropertyPlaceholderConfigurer itself.
5455
return org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class;
5556
}
5657

src/docs/asciidoc/core/core-appendix.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,10 @@ available to you:
563563
==== Using `<property-placeholder/>`
564564

565565
This element activates the replacement of `${...}` placeholders, which are resolved against a
566-
specified properties file (as a <<core.adoc#resources,Spring resource location>>). This element is
567-
a convenience mechanism that sets up a <<core.adoc#beans-factory-placeholderconfigurer,
568-
`PropertyPlaceholderConfigurer`>> for you. If you need more control over the
569-
`PropertyPlaceholderConfigurer`, you can explicitly define one yourself.
566+
specified properties file (as a <<core.adoc#resources,Spring resource location>>). This element
567+
is a convenience mechanism that sets up a <<core.adoc#beans-factory-placeholderconfigurer,
568+
`PropertySourcesPlaceholderConfigurer`>> for you. If you need more control over the
569+
`PropertySourcesPlaceholderConfigurer`, you can explicitly define one yourself.
570570

571571

572572

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ The following example shows the basic structure of XML-based configuration metad
163163
<2> The `class` attribute defines the type of the bean and uses the fully qualified
164164
classname.
165165

166-
167166
The value of the `id` attribute refers to collaborating objects. The XML for
168167
referring to collaborating objects is not shown in this example. See
169168
<<beans-dependencies,Dependencies>> for more information.
@@ -1355,7 +1354,7 @@ You can also configure a `java.util.Properties` instance, as follows:
13551354
[subs="verbatim,quotes"]
13561355
----
13571356
<bean id="mappings"
1358-
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
1357+
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
13591358
13601359
<!-- typed as a java.util.Properties -->
13611360
<property name="properties">
@@ -3980,19 +3979,19 @@ to work with bean instances within a `BeanFactoryPostProcessor` (for example, by
39803979
standard container lifecycle. This may cause negative side effects, such as bypassing
39813980
bean post processing.
39823981
3983-
Also, `BeanFactoryPostProcessor` instances are scoped per-container. This is only relevant if
3984-
you use container hierarchies. If you define a `BeanFactoryPostProcessor` in one
3985-
container, it is applied only to the bean definitions in that container. Bean
3986-
definitions in one container are not post-processed by `BeanFactoryPostProcessor` instances
3987-
in another container, even if both containers are part of the same hierarchy.
3982+
Also, `BeanFactoryPostProcessor` instances are scoped per-container. This is only relevant
3983+
if you use container hierarchies. If you define a `BeanFactoryPostProcessor` in one
3984+
container, it is applied only to the bean definitions in that container. Bean definitions
3985+
in one container are not post-processed by `BeanFactoryPostProcessor` instances in another
3986+
container, even if both containers are part of the same hierarchy.
39883987
====
39893988

39903989
A bean factory post-processor is automatically executed when it is declared inside an
39913990
`ApplicationContext`, in order to apply changes to the configuration metadata that
39923991
define the container. Spring includes a number of predefined bean factory
39933992
post-processors, such as `PropertyOverrideConfigurer` and
3994-
`PropertyPlaceholderConfigurer`. You can also use a custom `BeanFactoryPostProcessor` --
3995-
for example, to register custom property editors.
3993+
`PropertySourcesPlaceholderConfigurer`. You can also use a custom `BeanFactoryPostProcessor`
3994+
-- for example, to register custom property editors.
39963995

39973996
An `ApplicationContext` automatically detects any beans that are deployed into it that
39983997
implement the `BeanFactoryPostProcessor` interface. It uses these beans as bean factory
@@ -4008,21 +4007,21 @@ Thus, marking it for lazy initialization will be ignored, and the
40084007

40094008

40104009
[[beans-factory-placeholderconfigurer]]
4011-
==== Example: The Class Name Substitution `PropertyPlaceholderConfigurer`
4010+
==== Example: The Class Name Substitution `PropertySourcesPlaceholderConfigurer`
40124011

4013-
You can use the `PropertyPlaceholderConfigurer` to externalize property values from a bean
4014-
definition in a separate file by using the standard Java `Properties` format. Doing so
4015-
enables the person deploying an application to customize environment-specific properties,
4016-
such as database URLs and passwords, without the complexity or risk of modifying the
4017-
main XML definition file or files for the container.
4012+
You can use the `PropertySourcesPlaceholderConfigurer` to externalize property values
4013+
from a bean definition in a separate file by using the standard Java `Properties` format.
4014+
Doing so enables the person deploying an application to customize environment-specific
4015+
properties, such as database URLs and passwords, without the complexity or risk of
4016+
modifying the main XML definition file or files for the container.
40184017

40194018
Consider the following XML-based configuration metadata fragment, where a `DataSource`
40204019
with placeholder values is defined:
40214020

40224021
[source,xml,indent=0]
40234022
[subs="verbatim,quotes"]
40244023
----
4025-
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
4024+
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
40264025
<property name="locations" value="classpath:com/something/jdbc.properties"/>
40274026
</bean>
40284027
@@ -4035,11 +4034,10 @@ with placeholder values is defined:
40354034
</bean>
40364035
----
40374036

4038-
The example shows properties configured from an
4039-
external `Properties` file. At runtime, a `PropertyPlaceholderConfigurer` is applied to
4040-
the metadata that replaces some properties of the DataSource. The values to replace
4041-
are specified as placeholders of the form `${property-name}`, which follows the Ant and
4042-
log4j and JSP EL style.
4037+
The example shows properties configured from an external `Properties` file. At runtime,
4038+
a `PropertySourcesPlaceholderConfigurer` is applied to the metadata that replaces some
4039+
properties of the DataSource. The values to replace are specified as placeholders of the
4040+
form `${property-name}`, which follows the Ant and log4j and JSP EL style.
40434041

40444042
The actual values come from another file in the standard Java `Properties` format:
40454043

@@ -4054,43 +4052,33 @@ jdbc.password=root
40544052

40554053
Therefore, the `${jdbc.username}` string is replaced at runtime with the value, 'sa', and
40564054
the same applies for other placeholder values that match keys in the properties file.
4057-
The `PropertyPlaceholderConfigurer` checks for placeholders in most properties and
4055+
The `PropertySourcesPlaceholderConfigurer` checks for placeholders in most properties and
40584056
attributes of a bean definition. Furthermore, you can customize the placeholder prefix and suffix.
40594057

4060-
With the `context` namespace introduced in Spring 2.5, you can configure
4061-
property placeholders with a dedicated configuration element. You can provide one or more locations
4062-
as a comma-separated list in the `location` attribute, as the following example shows:
4058+
With the `context` namespace introduced in Spring 2.5, you can configure property placeholders
4059+
with a dedicated configuration element. You can provide one or more locations as a
4060+
comma-separated list in the `location` attribute, as the following example shows:
40634061

40644062
[source,xml,indent=0]
40654063
[subs="verbatim,quotes"]
40664064
----
40674065
<context:property-placeholder location="classpath:com/something/jdbc.properties"/>
40684066
----
40694067

4070-
The `PropertyPlaceholderConfigurer` not only looks for properties in the `Properties`
4071-
file you specify. By default, if it
4072-
cannot find a property in the specified properties files, it also checks against the Java `System` properties. You can customize this
4073-
behavior by setting the `systemPropertiesMode` property of the configurer with one of
4074-
the following three supported integer values:
4075-
4076-
* `never` (0): Never check system properties.
4077-
* `fallback` (1): Check system properties if not resolvable in the specified
4078-
properties files. This is the default.
4079-
* `override` (2): Check system properties first, before trying the specified
4080-
properties files. This lets system properties override any other property source.
4081-
4082-
See the {api-spring-framework}/beans/factory/config/PropertyPlaceholderConfigurer.html[`PropertyPlaceholderConfigurer`] javadoc for more information.
4068+
The `PropertySourcesPlaceholderConfigurer` not only looks for properties in the `Properties`
4069+
file you specify. By default, if it cannot find a property in the specified properties files,
4070+
it checks against Spring `Environment` properties and regular Java `System` properties.
40834071

40844072
[TIP]
40854073
=====
4086-
You can use the `PropertyPlaceholderConfigurer` to substitute class names, which is
4087-
sometimes useful when you have to pick a particular implementation class at runtime. The
4088-
following example shows how to do so:
4074+
You can use the `PropertySourcesPlaceholderConfigurer` to substitute class names, which
4075+
is sometimes useful when you have to pick a particular implementation class at runtime.
4076+
The following example shows how to do so:
40894077
40904078
[source,xml,indent=0]
40914079
[subs="verbatim,quotes"]
40924080
----
4093-
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
4081+
<bean class="org.springframework.beans.factory.config.PropertySourcesPlaceholderConfigurer">
40944082
<property name="locations">
40954083
<value>classpath:com/something/strategy.properties</value>
40964084
</property>
@@ -4112,8 +4100,8 @@ phase of an `ApplicationContext` for a non-lazy-init bean.
41124100
==== Example: The `PropertyOverrideConfigurer`
41134101

41144102
The `PropertyOverrideConfigurer`, another bean factory post-processor, resembles the
4115-
`PropertyPlaceholderConfigurer`, but unlike the latter, the original definitions can
4116-
have default values or no values at all for bean properties. If an overriding
4103+
`PropertySourcesPlaceholderConfigurer`, but unlike the latter, the original definitions
4104+
can have default values or no values at all for bean properties. If an overriding
41174105
`Properties` file does not have an entry for a certain bean property, the default
41184106
context definition is used.
41194107

@@ -9030,7 +9018,7 @@ you need to call its `postProcessBeanFactory` method, as the following example s
90309018
reader.loadBeanDefinitions(new FileSystemResource("beans.xml"));
90319019
90329020
// bring in some property values from a Properties file
9033-
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
9021+
PropertySourcesPlaceholderConfigurer cfg = new PropertySourcesPlaceholderConfigurer();
90349022
cfg.setLocation(new FileSystemResource("jdbc.properties"));
90359023
90369024
// now actually do the replacement

0 commit comments

Comments
 (0)