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:
@@ -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]]
|
||||
|
||||
Reference in New Issue
Block a user