Revised alias definition example in reference documentation

Issue: SPR-17536
This commit is contained in:
Juergen Hoeller 2018-11-25 21:27:49 +01:00
parent ebbe14c363
commit 80b8382f00
1 changed files with 10 additions and 10 deletions

View File

@ -565,9 +565,9 @@ itself.
Specifying all aliases where the bean is actually defined is not always adequate, Specifying all aliases where the bean is actually defined is not always adequate,
however. It is sometimes desirable to introduce an alias for a bean that is defined however. It is sometimes desirable to introduce an alias for a bean that is defined
elsewhere. This is commonly the case in large systems where configuration is split elsewhere. This is commonly the case in large systems where configuration is split
amongst each subsystem, with each subsystem having its own set of object definitions. In amongst each subsystem, with each subsystem having its own set of object definitions.
XML-based configuration metadata, you can use the `<alias/>` element to accomplish this. In XML-based configuration metadata, you can use the `<alias/>` element to accomplish
The following example shows how to do so: this. The following example shows how to do so:
==== ====
[source,xml,indent=0] [source,xml,indent=0]
@ -580,19 +580,19 @@ The following example shows how to do so:
In this case, a bean (in the same container) 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 by For example, the configuration metadata for subsystem A may refer to a DataSource by the
the name of `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 by the name of `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 by the that uses both these subsystems, the main application refers to the DataSource by the
name of `myApp-dataSource`. To have all three names refer to the same object, you can add name of `myApp-dataSource`. To have all three names refer to the same object, you can
the following alias definitions to the configuration metadata: 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"/>
---- ----
==== ====
@ -7231,7 +7231,7 @@ a number of aliases for a bean:
@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...
} }