@@ -163,7 +163,6 @@ The following example shows the basic structure of XML-based configuration metad
163
163
<2> The `class` attribute defines the type of the bean and uses the fully qualified
164
164
classname.
165
165
166
-
167
166
The value of the `id` attribute refers to collaborating objects. The XML for
168
167
referring to collaborating objects is not shown in this example. See
169
168
<<beans-dependencies,Dependencies>> for more information.
@@ -1355,7 +1354,7 @@ You can also configure a `java.util.Properties` instance, as follows:
1355
1354
[subs="verbatim,quotes"]
1356
1355
----
1357
1356
<bean id="mappings"
1358
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
1357
+ class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer ">
1359
1358
1360
1359
<!-- typed as a java.util.Properties -->
1361
1360
<property name="properties">
@@ -3980,19 +3979,19 @@ to work with bean instances within a `BeanFactoryPostProcessor` (for example, by
3980
3979
standard container lifecycle. This may cause negative side effects, such as bypassing
3981
3980
bean post processing.
3982
3981
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.
3988
3987
====
3989
3988
3990
3989
A bean factory post-processor is automatically executed when it is declared inside an
3991
3990
`ApplicationContext`, in order to apply changes to the configuration metadata that
3992
3991
define the container. Spring includes a number of predefined bean factory
3993
3992
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.
3996
3995
3997
3996
An `ApplicationContext` automatically detects any beans that are deployed into it that
3998
3997
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
4008
4007
4009
4008
4010
4009
[[beans-factory-placeholderconfigurer]]
4011
- ==== Example: The Class Name Substitution `PropertyPlaceholderConfigurer `
4010
+ ==== Example: The Class Name Substitution `PropertySourcesPlaceholderConfigurer `
4012
4011
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.
4018
4017
4019
4018
Consider the following XML-based configuration metadata fragment, where a `DataSource`
4020
4019
with placeholder values is defined:
4021
4020
4022
4021
[source,xml,indent=0]
4023
4022
[subs="verbatim,quotes"]
4024
4023
----
4025
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
4024
+ <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer ">
4026
4025
<property name="locations" value="classpath:com/something/jdbc.properties"/>
4027
4026
</bean>
4028
4027
@@ -4035,11 +4034,10 @@ with placeholder values is defined:
4035
4034
</bean>
4036
4035
----
4037
4036
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.
4043
4041
4044
4042
The actual values come from another file in the standard Java `Properties` format:
4045
4043
@@ -4054,43 +4052,33 @@ jdbc.password=root
4054
4052
4055
4053
Therefore, the `${jdbc.username}` string is replaced at runtime with the value, 'sa', and
4056
4054
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
4058
4056
attributes of a bean definition. Furthermore, you can customize the placeholder prefix and suffix.
4059
4057
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:
4063
4061
4064
4062
[source,xml,indent=0]
4065
4063
[subs="verbatim,quotes"]
4066
4064
----
4067
4065
<context:property-placeholder location="classpath:com/something/jdbc.properties"/>
4068
4066
----
4069
4067
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.
4083
4071
4084
4072
[TIP]
4085
4073
=====
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:
4089
4077
4090
4078
[source,xml,indent=0]
4091
4079
[subs="verbatim,quotes"]
4092
4080
----
4093
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
4081
+ <bean class="org.springframework.beans.factory.config.PropertySourcesPlaceholderConfigurer ">
4094
4082
<property name="locations">
4095
4083
<value>classpath:com/something/strategy.properties</value>
4096
4084
</property>
@@ -4112,8 +4100,8 @@ phase of an `ApplicationContext` for a non-lazy-init bean.
4112
4100
==== Example: The `PropertyOverrideConfigurer`
4113
4101
4114
4102
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
4117
4105
`Properties` file does not have an entry for a certain bean property, the default
4118
4106
context definition is used.
4119
4107
@@ -9030,7 +9018,7 @@ you need to call its `postProcessBeanFactory` method, as the following example s
9030
9018
reader.loadBeanDefinitions(new FileSystemResource("beans.xml"));
9031
9019
9032
9020
// bring in some property values from a Properties file
9033
- PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer ();
9021
+ PropertySourcesPlaceholderConfigurer cfg = new PropertySourcesPlaceholderConfigurer ();
9034
9022
cfg.setLocation(new FileSystemResource("jdbc.properties"));
9035
9023
9036
9024
// now actually do the replacement
0 commit comments