@@ -119,11 +119,12 @@ as shown below.
119
119
byte[] bytes = (byte[]) exp.getValue();
120
120
----
121
121
122
- SpEL also supports nested properties using the standard _dot_ notation, i.e.
123
- `prop1.prop2.prop3` and also the corresponding setting of property values.
124
-
122
+ SpEL also supports nested properties by using the standard dot notation (such as
123
+ `prop1.prop2.prop3`) and also the corresponding setting of property values.
125
124
Public fields may also be accessed.
126
125
126
+ The following example shows how to use dot notation to get the length of a literal:
127
+
127
128
[source,java,indent=0]
128
129
[subs="verbatim,quotes"]
129
130
----
@@ -287,22 +288,21 @@ It is also possible to configure the behaviour of the SpEL expression compiler.
287
288
=== SpEL compilation
288
289
289
290
Spring Framework 4.1 includes a basic expression compiler. Expressions are usually
290
- interpreted which provides a lot of dynamic flexibility during evaluation but
291
- does not provide optimum performance. For occasional expression usage
292
- this is fine, but when used by other components like Spring Integration,
293
- performance can be very important and there is no real need for the dynamism.
294
-
295
- The SpEL compiler is intended to address this need. The compiler will generate a
296
- real Java class on the fly during evaluation that embodies the expression behavior
297
- and use that to achieve much faster expression evaluation. Due to the lack of
298
- typing around expressions the compiler uses information gathered during the
299
- interpreted evaluations of an expression when performing compilation. For example,
300
- it does not know the type of a property reference purely from the expression but
301
- during the first interpreted evaluation it will find out what it is. Of course,
302
- basing the compilation on this information could cause trouble later if the types
303
- of the various expression elements change over time. For this reason compilation
304
- is best suited to expressions whose type information is not going to change on
305
- repeated evaluations.
291
+ interpreted, which provides a lot of dynamic flexibility during evaluation but
292
+ does not provide optimum performance. For occasional expression usage,
293
+ this is fine, but, when used by other components such as Spring Integration,
294
+ performance can be very important, and there is no real need for the dynamism.
295
+
296
+ The SpEL compiler is intended to address this need. During evaluation, the compiler
297
+ generates a Java class that embodies the expression behavior at runtime and uses that
298
+ class to achieve much faster expression evaluation. Due to the lack of typing around
299
+ expressions, the compiler uses information gathered during the interpreted evaluations
300
+ of an expression when performing compilation. For example, it does not know the type
301
+ of a property reference purely from the expression, but during the first interpreted
302
+ evaluation, it finds out what it is. Of course, basing compilation on such derived
303
+ information can cause trouble later if the types of the various expression elements
304
+ change over time. For this reason, compilation is best suited to expressions whose
305
+ type information is not going to change on repeated evaluations.
306
306
307
307
For a basic expression like this:
308
308
@@ -360,24 +360,24 @@ After selecting a mode, use the `SpelParserConfiguration` to configure the parse
360
360
Object payload = expr.getValue(message);
361
361
----
362
362
363
- When specifying the compiler mode it is also possible to specify a classloader (passing null is allowed).
364
- Compiled expressions will be defined in a child classloader created under any that is supplied.
365
- It is important to ensure if a classloader is specified it can see all the types involved in
366
- the expression evaluation process. If none is specified then a default classloader will be used
363
+ When you specify the compiler mode, you can also specify a classloader (passing null is allowed).
364
+ Compiled expressions are defined in a child classloader created under any that is supplied.
365
+ It is important to ensure that, if a classloader is specified, it can see all the types involved in
366
+ the expression evaluation process. If you do not specify a classloader, a default classloader is used
367
367
(typically the context classloader for the thread that is running during expression evaluation).
368
368
369
369
The second way to configure the compiler is for use when SpEL is embedded inside some other
370
- component and it may not be possible to configure via a configuration object. In these cases
371
- it is possible to use a system property. The property `spring.expression.compiler.mode` can be
372
- set to one of the `SpelCompilerMode` enum values (`off`, `immediate`, or `mixed`).
370
+ component and it may not be possible to configure it through a configuration object. In these
371
+ cases, it is possible to use a system property. You can set the `spring.expression.compiler.mode`
372
+ property to one of the `SpelCompilerMode` enum values (`off`, `immediate`, or `mixed`).
373
373
374
374
375
375
[[expressions-compiler-limitations]]
376
376
==== Compiler limitations
377
377
378
- Since Spring Framework 4.1 the basic compilation framework is in place. However, the framework
378
+ Since Spring Framework 4.1, the basic compilation framework is in place. However, the framework
379
379
does not yet support compiling every kind of expression. The initial focus has been on the
380
- common expressions that are likely to be used in performance critical contexts. The following
380
+ common expressions that are likely to be used in performance- critical contexts. The following
381
381
kinds of expression cannot be compiled at the moment:
382
382
383
383
- expressions involving assignment
0 commit comments