Currently the document only mentioned systemProperties as predefined variable, actually all builtin beans registered by AbstractApplicationContext are predefined variables, such as environment and systemEnvironment and messageSource and applicationEventMulticaster and lifecycleProcessor. It's worthy to add a new section describe those predefined variables.
Comment From: quaff
Same for javadoc of StandardBeanExpressionResolver
Comment From: quaff
https://github.com/spring-projects/spring-framework/blob/master/src/docs/asciidoc/core/core-expressions.adoc#the-elvis-operator
ExpressionParser parser = new SpelExpressionParser();
String name = parser.parseExpression("name?:'Unknown'").getValue(String.class);
System.out.println(name); // 'Unknown'
It throws exception instead of print Unknown because no variable name defined
Exception in thread "main" org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'name' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91)
at org.springframework.expression.spel.ast.Elvis.getValueInternal(Elvis.java:53)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:117)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:177)
Comment From: sbrannen
It throws exception instead of print
Unknownbecause no variable name defined
Can you please open a separate issue for that?
Comment From: quaff
It throws exception instead of print
Unknownbecause no variable name definedCan you please open a separate issue for that?
@sbrannen I've created https://github.com/spring-projects/spring-framework/pull/25045
Comment From: jhoeller
I've revised the entire section a bit, adding a note that generally all beans in the context are available as predefined variables in SpEL expressions, including standard context beans... singling out environment, systemProperties and systemEnvironment (including their exposed Java type). This should cover all common cases since SPI beans in the context are really not meant to be commonly accessed in SpEL expressions.