Enum Class SpelCompilerMode

java.lang.Object
java.lang.Enum<SpelCompilerMode>
org.springframework.expression.spel.SpelCompilerMode
All Implemented Interfaces:
Serializable, Comparable<SpelCompilerMode>, Constable

public enum SpelCompilerMode extends Enum<SpelCompilerMode>
Captures the possible configuration settings for a compiler that can be used when evaluating expressions.

Spring provides a basic compiler for SpEL expressions. Expressions are usually interpreted, which provides a lot of dynamic flexibility during evaluation but does not provide optimum performance. For occasional expression usage, this is fine, but when used by other components such as Spring Integration, performance can be very important, and there is no real need for the dynamism.

The SpEL compiler is intended to address this need. During evaluation, the compiler generates a Java class that embodies the expression behavior at runtime and uses that class to achieve much faster expression evaluation. Due to the lack of typing around expressions, the compiler uses information gathered during the interpreted evaluations of an expression when performing compilation. For example, SpEL does not know the type of a property reference purely from the expression, but during the first interpreted evaluation, it finds out what it is. Of course, basing compilation on such derived information can cause trouble later if the types of the various expression elements change over time. For this reason, compilation is best suited to expressions whose type information is not going to change on repeated evaluations.

Since:
4.1
Author:
Andy Clement, Sam Brannen
  • Enum Constant Details

    • OFF

      public static final SpelCompilerMode OFF
      The compiler is turned off, and all expressions will be evaluated in interpreted mode.

      This is the default.

    • IMMEDIATE

      public static final SpelCompilerMode IMMEDIATE
      In immediate mode, expressions are compiled as soon as possible, typically after the first interpreted evaluation.

      If evaluation of the compiled expression fails (for example, due to a type changing), the caller of the expression evaluation receives an exception.

      If the types of various expression elements change over time, consider switching to MIXED mode or turning off the compiler.

    • MIXED

      public static final SpelCompilerMode MIXED
      In mixed mode, expression evaluation silently switches between interpreted and compiled over time.

      After some number of successful interpreted runs, the expression gets compiled. If evaluation of the compiled expression fails (for example, due to a type changing), that failure will be caught internally, and the system will switch back to interpreted mode for the given expression. Basically, the exception that the caller receives in IMMEDIATE mode is instead handled internally. Sometime later, the compiler may generate another compiled form and switch to it. This cycle of switching between interpreted and compiled mode will continue until the system determines that it does not make sense to continue trying — for example, when a certain failure threshold has been reached — at which point the system will permanently switch to interpreted mode for the given expression.

  • Method Details

    • values

      public static SpelCompilerMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SpelCompilerMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null