From 0f1cae6d53a395e34998489f54213e4b708d6811 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 18 May 2020 14:19:05 +0200 Subject: [PATCH] Explicit notes on access to standard context beans in SpEL expressions Closes gh-25037 --- .../StandardBeanExpressionResolver.java | 7 ++++++- src/docs/asciidoc/core/core-expressions.adoc | 15 +++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java b/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java index dc058f15847d..c2a0235d1972 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java +++ b/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,8 +41,13 @@ * {@link org.springframework.beans.factory.config.BeanExpressionResolver} * interface, parsing and evaluating Spring EL using Spring's expression module. * + *

All beans in the containing {@code BeanFactory} are made available as + * predefined variables with their common bean name, including standard context + * beans such as "environment", "systemProperties" and "systemEnvironment". + * * @author Juergen Hoeller * @since 3.0 + * @see BeanExpressionContext#getBeanFactory() * @see org.springframework.expression.ExpressionParser * @see org.springframework.expression.spel.standard.SpelExpressionParser * @see org.springframework.expression.spel.support.StandardEvaluationContext diff --git a/src/docs/asciidoc/core/core-expressions.adoc b/src/docs/asciidoc/core/core-expressions.adoc index ee7eae224dc4..729ae85a91a1 100644 --- a/src/docs/asciidoc/core/core-expressions.adoc +++ b/src/docs/asciidoc/core/core-expressions.adoc @@ -539,8 +539,12 @@ example shows: ---- -The `systemProperties` variable is predefined, so you can use it in your expressions, as -the following example shows: +All beans in the application context are available as predefined variables with their +common bean name. This includes standard context beans such as `environment` (of type +`org.springframework.core.env.Environment`) as well as `systemProperties` and +`systemEnvironment` (of type `Map`) for access to the runtime environment. + +The following example shows access to the `systemProperties` bean as a SpEL variable: [source,xml,indent=0,subs="verbatim"] ---- @@ -551,8 +555,7 @@ the following example shows: ---- -Note that you do not have to prefix the predefined variable with the `#` -symbol in this context. +Note that you do not have to prefix the predefined variable with the `#` symbol here. You can also refer to other bean properties by name, as the following example shows: @@ -576,8 +579,8 @@ You can also refer to other bean properties by name, as the following example sh [[expressions-beandef-annotation-based]] === Annotation Configuration -To specify a default value, you can place the `@Value` annotation on fields, methods, and method or constructor -parameters. +To specify a default value, you can place the `@Value` annotation on fields, methods, +and method or constructor parameters. The following example sets the default value of a field variable: