Skip to content

Commit 32a5830

Browse files
committed
Ensure code listing callouts are displayed incorrectly in core-beans.adoc
Closes gh-29457
1 parent 9378493 commit 32a5830

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,6 +5200,7 @@ with specific arguments, narrowing the set of type matches so that a specific be
52005200
chosen for each argument. In the simplest case, this can be a plain descriptive value, as
52015201
shown in the following example:
52025202

5203+
--
52035204
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
52045205
.Java
52055206
----
@@ -5224,10 +5225,12 @@ shown in the following example:
52245225
// ...
52255226
}
52265227
----
5228+
--
52275229

52285230
You can also specify the `@Qualifier` annotation on individual constructor arguments or
52295231
method parameters, as shown in the following example:
52305232

5233+
--
52315234
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
52325235
.Java
52335236
----
@@ -5266,9 +5269,11 @@ method parameters, as shown in the following example:
52665269
// ...
52675270
}
52685271
----
5272+
--
52695273

52705274
The following example shows corresponding bean definitions.
52715275

5276+
--
52725277
[source,xml,indent=0,subs="verbatim,quotes"]
52735278
----
52745279
<?xml version="1.0" encoding="UTF-8"?>
@@ -5302,6 +5307,7 @@ The following example shows corresponding bean definitions.
53025307
is qualified with the same value.
53035308
<2> The bean with the `action` qualifier value is wired with the constructor argument that
53045309
is qualified with the same value.
5310+
--
53055311

53065312
For a fallback match, the bean name is considered a default qualifier value. Thus, you
53075313
can define the bean with an `id` of `main` instead of the nested qualifier element, leading
@@ -5379,6 +5385,7 @@ constructor or a multi-argument method.
53795385
You can create your own custom qualifier annotations. To do so, define an annotation and
53805386
provide the `@Qualifier` annotation within your definition, as the following example shows:
53815387

5388+
--
53825389
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
53835390
.Java
53845391
----
@@ -5398,10 +5405,12 @@ provide the `@Qualifier` annotation within your definition, as the following exa
53985405
@Qualifier
53995406
annotation class Genre(val value: String)
54005407
----
5408+
--
54015409

54025410
Then you can provide the custom qualifier on autowired fields and parameters, as the
54035411
following example shows:
54045412

5413+
--
54055414
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
54065415
.Java
54075416
----
@@ -5440,6 +5449,7 @@ following example shows:
54405449
// ...
54415450
}
54425451
----
5452+
--
54435453

54445454
Next, you can provide the information for the candidate bean definitions. You can add
54455455
`<qualifier/>` tags as sub-elements of the `<bean/>` tag and then specify the `type` and
@@ -5448,6 +5458,7 @@ fully-qualified class name of the annotation. Alternately, as a convenience if n
54485458
conflicting names exists, you can use the short class name. The following example
54495459
demonstrates both approaches:
54505460

5461+
--
54515462
[source,xml,indent=0,subs="verbatim,quotes"]
54525463
----
54535464
<?xml version="1.0" encoding="UTF-8"?>
@@ -5475,6 +5486,7 @@ demonstrates both approaches:
54755486
54765487
</beans>
54775488
----
5489+
--
54785490

54795491
In <<beans-classpath-scanning>>, you can see an annotation-based alternative to
54805492
providing the qualifier metadata in XML. Specifically, see <<beans-scanning-qualifiers>>.
@@ -5485,6 +5497,7 @@ several different types of dependencies. For example, you may provide an offline
54855497
catalog that can be searched when no Internet connection is available. First, define
54865498
the simple annotation, as the following example shows:
54875499

5500+
--
54885501
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
54895502
.Java
54905503
----
@@ -5502,10 +5515,12 @@ the simple annotation, as the following example shows:
55025515
@Qualifier
55035516
annotation class Offline
55045517
----
5518+
--
55055519

55065520
Then add the annotation to the field or property to be autowired, as shown in the
55075521
following example:
55085522

5523+
--
55095524
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
55105525
.Java
55115526
----
@@ -5533,9 +5548,11 @@ class MovieRecommender {
55335548
}
55345549
----
55355550
<1> This line adds the `@Offline` annotation.
5551+
--
55365552

55375553
Now the bean definition only needs a qualifier `type`, as shown in the following example:
55385554

5555+
--
55395556
[source,xml,indent=0,subs="verbatim,quotes"]
55405557
----
55415558
<bean class="example.SimpleMovieCatalog">
@@ -5544,6 +5561,7 @@ Now the bean definition only needs a qualifier `type`, as shown in the following
55445561
</bean>
55455562
----
55465563
<1> This element specifies the qualifier.
5564+
--
55475565

55485566

55495567
You can also define custom qualifier annotations that accept named attributes in
@@ -5552,6 +5570,7 @@ then specified on a field or parameter to be autowired, a bean definition must m
55525570
all such attribute values to be considered an autowire candidate. As an example,
55535571
consider the following annotation definition:
55545572

5573+
--
55555574
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
55565575
.Java
55575576
----
@@ -5573,9 +5592,11 @@ consider the following annotation definition:
55735592
@Qualifier
55745593
annotation class MovieQualifier(val genre: String, val format: Format)
55755594
----
5595+
--
55765596

55775597
In this case `Format` is an enum, defined as follows:
55785598

5599+
--
55795600
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
55805601
.Java
55815602
----
@@ -5590,10 +5611,12 @@ In this case `Format` is an enum, defined as follows:
55905611
VHS, DVD, BLURAY
55915612
}
55925613
----
5614+
--
55935615

55945616
The fields to be autowired are annotated with the custom qualifier and include values
55955617
for both attributes: `genre` and `format`, as the following example shows:
55965618

5619+
--
55975620
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
55985621
.Java
55995622
----
@@ -5642,6 +5665,7 @@ for both attributes: `genre` and `format`, as the following example shows:
56425665
// ...
56435666
}
56445667
----
5668+
--
56455669

56465670
Finally, the bean definitions should contain matching qualifier values. This example
56475671
also demonstrates that you can use bean meta attributes instead of the
@@ -5650,6 +5674,7 @@ precedence, but the autowiring mechanism falls back on the values provided withi
56505674
`<meta/>` tags if no such qualifier is present, as in the last two bean definitions in
56515675
the following example:
56525676

5677+
--
56535678
[source,xml,indent=0,subs="verbatim,quotes"]
56545679
----
56555680
<?xml version="1.0" encoding="UTF-8"?>
@@ -5693,6 +5718,7 @@ the following example:
56935718
56945719
</beans>
56955720
----
5721+
--
56965722

56975723

56985724

@@ -5824,6 +5850,7 @@ endpoints. Spring supports this pattern for Spring-managed objects as well.
58245850
the bean name to be injected. In other words, it follows by-name semantics,
58255851
as demonstrated in the following example:
58265852

5853+
--
58275854
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
58285855
.Java
58295856
----
@@ -5849,13 +5876,15 @@ class SimpleMovieLister {
58495876
}
58505877
----
58515878
<1> This line injects a `@Resource`.
5879+
--
58525880

58535881

58545882
If no name is explicitly specified, the default name is derived from the field name or
58555883
setter method. In case of a field, it takes the field name. In case of a setter method,
58565884
it takes the bean property name. The following example is going to have the bean
58575885
named `movieFinder` injected into its setter method:
58585886

5887+
--
58595888
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
58605889
.Java
58615890
----
@@ -5879,6 +5908,7 @@ named `movieFinder` injected into its setter method:
58795908
58805909
}
58815910
----
5911+
--
58825912

58835913
NOTE: The name provided with the annotation is resolved as a bean name by the
58845914
`ApplicationContext` of which the `CommonAnnotationBeanPostProcessor` is aware.
@@ -5897,6 +5927,7 @@ Thus, in the following example, the `customerPreferenceDao` field first looks fo
58975927
named "customerPreferenceDao" and then falls back to a primary type match for the type
58985928
`CustomerPreferenceDao`:
58995929

5930+
--
59005931
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
59015932
.Java
59025933
----
@@ -5934,6 +5965,7 @@ named "customerPreferenceDao" and then falls back to a primary type match for th
59345965
----
59355966
<1> The `context` field is injected based on the known resolvable dependency type:
59365967
`ApplicationContext`.
5968+
--
59375969

59385970
[[beans-value-annotations]]
59395971
=== Using `@Value`
@@ -9489,6 +9521,7 @@ annotation lets you indicate that a component is eligible for registration
94899521
when one or more specified profiles are active. Using our preceding example, we
94909522
can rewrite the `dataSource` configuration as follows:
94919523

9524+
--
94929525
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
94939526
.Java
94949527
----
@@ -9523,7 +9556,9 @@ can rewrite the `dataSource` configuration as follows:
95239556
}
95249557
}
95259558
----
9559+
--
95269560

9561+
--
95279562
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
95289563
.Java
95299564
----
@@ -9555,6 +9590,7 @@ can rewrite the `dataSource` configuration as follows:
95559590
}
95569591
----
95579592
<1> `@Bean(destroyMethod = "")` disables default destroy method inference.
9593+
--
95589594

95599595
NOTE: As mentioned earlier, with `@Bean` methods, you typically choose to use programmatic
95609596
JNDI lookups, by using either Spring's `JndiTemplate`/`JndiLocatorDelegate` helpers or the
@@ -9579,6 +9615,7 @@ of creating a custom composed annotation. The following example defines a custom
95799615
`@Production` annotation that you can use as a drop-in replacement for
95809616
`@Profile("production")`:
95819617

9618+
--
95829619
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
95839620
.Java
95849621
----
@@ -9596,6 +9633,7 @@ of creating a custom composed annotation. The following example defines a custom
95969633
@Profile("production")
95979634
annotation class Production
95989635
----
9636+
--
95999637

96009638
TIP: If a `@Configuration` class is marked with `@Profile`, all of the `@Bean` methods and
96019639
`@Import` annotations associated with that class are bypassed unless one or more of
@@ -9610,6 +9648,7 @@ active. For example, given `@Profile({"p1", "!p2"})`, registration will occur if
96109648
of a configuration class (for example, for alternative variants of a particular bean), as
96119649
the following example shows:
96129650

9651+
--
96139652
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
96149653
.Java
96159654
----
@@ -9661,6 +9700,7 @@ the following example shows:
96619700
----
96629701
<1> The `standaloneDataSource` method is available only in the `development` profile.
96639702
<2> The `jndiDataSource` method is available only in the `production` profile.
9703+
--
96649704

96659705
[NOTE]
96669706
====

0 commit comments

Comments
 (0)