Skip to content

Commit 4f607b5

Browse files
committed
Improve document for SpEL Bean References
1 parent eab9607 commit 4f607b5

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

framework-docs/modules/ROOT/pages/core/expressions/language-ref/bean-references.adoc

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[expressions-bean-references]]
22
= Bean References
33

4-
If the evaluation context has been configured with a bean resolver, you can
5-
look up beans from an expression by using the `@` symbol. The following example shows how
4+
If the evaluation context has been configured with a bean resolver, you can look up beans
5+
from an expression by using the `@` symbol as a prefix. The following example shows how
66
to do so:
77

88
[tabs]
@@ -15,8 +15,9 @@ Java::
1515
StandardEvaluationContext context = new StandardEvaluationContext();
1616
context.setBeanResolver(new MyBeanResolver());
1717
18-
// This will end up calling resolve(context,"something") on MyBeanResolver during evaluation
19-
Object bean = parser.parseExpression("@something").getValue(context);
18+
// This will end up calling resolve(context, "someBean") on MyBeanResolver
19+
// during evaluation.
20+
Object bean = parser.parseExpression("@someBean").getValue(context);
2021
----
2122
2223
Kotlin::
@@ -27,13 +28,20 @@ Kotlin::
2728
val context = StandardEvaluationContext()
2829
context.setBeanResolver(MyBeanResolver())
2930
30-
// This will end up calling resolve(context,"something") on MyBeanResolver during evaluation
31-
val bean = parser.parseExpression("@something").getValue(context)
31+
// This will end up calling resolve(context, "someBean") on MyBeanResolver
32+
// during evaluation.
33+
val bean = parser.parseExpression("@someBean").getValue(context)
3234
----
3335
======
3436

35-
To access a factory bean itself, you should instead prefix the bean name with an `&` symbol.
36-
The following example shows how to do so:
37+
[NOTE]
38+
====
39+
If a bean name contains a dot (`.`) or other special characters, you must provide the
40+
name of the bean as a _string literal_ – for example, `@'order.service'`.
41+
====
42+
43+
To access a factory bean itself, you should instead prefix the bean name with an `&`
44+
symbol. The following example shows how to do so:
3745

3846
[tabs]
3947
======
@@ -45,8 +53,9 @@ Java::
4553
StandardEvaluationContext context = new StandardEvaluationContext();
4654
context.setBeanResolver(new MyBeanResolver());
4755
48-
// This will end up calling resolve(context,"&foo") on MyBeanResolver during evaluation
49-
Object bean = parser.parseExpression("&foo").getValue(context);
56+
// This will end up calling resolve(context, "&someFactoryBean") on
57+
// MyBeanResolver during evaluation.
58+
Object factoryBean = parser.parseExpression("&someFactoryBean").getValue(context);
5059
----
5160
5261
Kotlin::
@@ -57,9 +66,8 @@ Kotlin::
5766
val context = StandardEvaluationContext()
5867
context.setBeanResolver(MyBeanResolver())
5968
60-
// This will end up calling resolve(context,"&foo") on MyBeanResolver during evaluation
61-
val bean = parser.parseExpression("&foo").getValue(context)
69+
// This will end up calling resolve(context, "&someFactoryBean") on
70+
// MyBeanResolver during evaluation.
71+
val factoryBean = parser.parseExpression("&someFactoryBean").getValue(context)
6272
----
6373
======
64-
65-

0 commit comments

Comments
 (0)