Revised alias definition example in reference documentation
Issue: SPR-17536
This commit is contained in:
@@ -545,21 +545,21 @@ XML-based configuration metadata, you can use the `<alias/>` element to accompli
|
|||||||
<alias name="fromName" alias="toName"/>
|
<alias name="fromName" alias="toName"/>
|
||||||
----
|
----
|
||||||
|
|
||||||
In this case, a bean in the same container which is named `fromName`, may also,
|
In this case, a bean (in the same container) named `fromName` may also,
|
||||||
after the use of this alias definition, be referred to as `toName`.
|
after the use of this alias definition, be referred to as `toName`.
|
||||||
|
|
||||||
For example, the configuration metadata for subsystem A may refer to a DataSource via
|
For example, the configuration metadata for subsystem A may refer to a DataSource by the
|
||||||
the name `subsystemA-dataSource`. The configuration metadata for subsystem B may refer to
|
name of `subsystemA-dataSource`. The configuration metadata for subsystem B may refer to
|
||||||
a DataSource via the name `subsystemB-dataSource`. When composing the main application
|
a DataSource by the name of `subsystemB-dataSource`. When composing the main application
|
||||||
that uses both these subsystems the main application refers to the DataSource via the
|
that uses both these subsystems, the main application refers to the DataSource by the
|
||||||
name `myApp-dataSource`. To have all three names refer to the same object you add to the
|
name of `myApp-dataSource`. To have all three names refer to the same object, you can
|
||||||
MyApp configuration metadata the following aliases definitions:
|
add the following alias definitions to the configuration metadata:
|
||||||
|
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
[subs="verbatim,quotes"]
|
[subs="verbatim,quotes"]
|
||||||
----
|
----
|
||||||
<alias name="subsystemA-dataSource" alias="subsystemB-dataSource"/>
|
<alias name="myApp-dataSource" alias="subsystemA-dataSource"/>
|
||||||
<alias name="subsystemA-dataSource" alias="myApp-dataSource" />
|
<alias name="myApp-dataSource" alias="subsystemB-dataSource"/>
|
||||||
----
|
----
|
||||||
|
|
||||||
Now each component and the main application can refer to the dataSource through a name
|
Now each component and the main application can refer to the dataSource through a name
|
||||||
@@ -6762,7 +6762,7 @@ annotation accepts a String array for this purpose.
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
|
|
||||||
@Bean(name = { "dataSource", "subsystemA-dataSource", "subsystemB-dataSource" })
|
@Bean({"dataSource", "subsystemA-dataSource", "subsystemB-dataSource"})
|
||||||
public DataSource dataSource() {
|
public DataSource dataSource() {
|
||||||
// instantiate, configure and return DataSource bean...
|
// instantiate, configure and return DataSource bean...
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user