Allow use of '&' prefix to access factory bean in SpEL

Prior to this change SpEL did not have an syntactic
construct enabling easy access to a FactoryBean. With this
change it is now possible to use &foo in an expression when
the factory bean should be returned.

Issue: SPR-9511
This commit is contained in:
Andy Clement
2016-01-21 16:14:16 -08:00
parent 415b2763ce
commit a12f23936c
9 changed files with 207 additions and 19 deletions

View File

@@ -1056,6 +1056,18 @@ lookup beans from an expression using the (@) symbol.
Object bean = parser.parseExpression("@foo").getValue(context);
----
To access a factory bean itself, the bean name should instead be prefixed with a (&) symbol.
[source,java,indent=0]
[subs="verbatim,quotes"]
----
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new MyBeanResolver());
// This will end up calling resolve(context,"&foo") on MyBeanResolver during evaluation
Object bean = parser.parseExpression("&foo").getValue(context);
----
[[expressions-operator-ternary]]