Class SpelParserConfiguration

java.lang.Object
org.springframework.expression.spel.SpelParserConfiguration

public class SpelParserConfiguration extends Object
Configuration object for the SpEL expression parser.

Rather than using one of the numerous constructors in this class, it is strongly recommended that you use the builder API to configure and create a SpelParserConfiguration instance, since the builder only requires configuration of the properties that need to deviate from their sensible defaults — or use withDefaults() if none of those defaults need to be overridden. Note that the constructors in this class are planned to be deprecated in favor of the builder as of Spring Framework 7.1.

Since:
3.0
Author:
Juergen Hoeller, Phillip Webb, Andy Clement, Sam Brannen
See Also:
  • Field Details

    • DEFAULT_MAX_EXPRESSION_LENGTH

      public static final int DEFAULT_MAX_EXPRESSION_LENGTH
      Default maximum length permitted for a SpEL expression: 10000.
      Since:
      5.2.24
      See Also:
    • DEFAULT_MAX_OPERATIONS

      public static final int DEFAULT_MAX_OPERATIONS
      Default maximum number of operations permitted during SpEL expression evaluation: 10000.
      Since:
      6.2.19
      See Also:
    • DEFAULT_MAX_BIG_POWER_BITS

      public static final int DEFAULT_MAX_BIG_POWER_BITS
      Default maximum number of bits permitted in the result of a BigDecimal or BigInteger power operation within a SpEL expression: 1000000.

      Approximately equivalent to a decimal number with 300,000 digits.

      Since:
      7.0.9
      See Also:
    • SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME

      public static final String SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME
      System property to configure the default compiler mode for SpEL expression parsers: "spring.expression.compiler.mode".

      NOTE: Instead of relying on a global default, applications and frameworks should ideally set an explicit custom value via SpelParserConfiguration.Builder.compilerMode(SpelCompilerMode), which provides complete configuration control and the ability to override global defaults per use case.

      Can also be configured via the SpringProperties mechanism.

      See Also:
    • SPRING_EXPRESSION_MAX_OPERATIONS_PROPERTY_NAME

      public static final String SPRING_EXPRESSION_MAX_OPERATIONS_PROPERTY_NAME
      System property to configure the default maximum number of operations permitted during SpEL expression evaluation: "spring.expression.maxOperations".

      NOTE: Instead of relying on a global default, applications and frameworks should ideally set an explicit custom value via SpelParserConfiguration.Builder.maximumOperations(int), which provides complete configuration control and the ability to override global defaults per use case.

      Can also be configured via the SpringProperties mechanism.

      Since:
      6.2.19
      See Also:
    • SPRING_EXPRESSION_MAX_BIG_POWER_BITS_PROPERTY_NAME

      public static final String SPRING_EXPRESSION_MAX_BIG_POWER_BITS_PROPERTY_NAME
      System property to configure the default maximum number of bits permitted in the result of a BigDecimal or BigInteger power operation within a SpEL expression: "spring.expression.maxBigPowerBits".

      NOTE: Instead of relying on a global default, applications and frameworks should ideally set an explicit custom value via SpelParserConfiguration.Builder.maximumBigPowerBits(int), which provides complete configuration control and the ability to override global defaults per use case.

      Can also be configured via the SpringProperties mechanism.

      Since:
      7.0.9
      See Also:
  • Constructor Details

    • SpelParserConfiguration

      public SpelParserConfiguration()
      Create a new SpelParserConfiguration instance with default settings.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(@Nullable SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      compilerMode - the compiler mode that parsers using this configuration should use; or null to use the default mode
      compilerClassLoader - the ClassLoader to use as the basis for expression compilation; or null to use the default ClassLoader
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(boolean autoGrowNullReferences, boolean autoGrowCollections)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      maximumAutoGrowSize - the maximum size to which a collection can auto grow
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(@Nullable SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      compilerMode - the compiler mode that parsers using this configuration should use; or null to use the default mode
      compilerClassLoader - the ClassLoader to use as the basis for expression compilation; or null to use the default ClassLoader
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      maximumAutoGrowSize - the maximum size to which a collection can auto grow
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(@Nullable SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize, int maximumExpressionLength)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      compilerMode - the compiler mode that parsers using this configuration should use; or null to use the default mode
      compilerClassLoader - the ClassLoader to use as the basis for expression compilation; or null to use the default ClassLoader
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      maximumAutoGrowSize - the maximum size to which a collection can auto grow
      maximumExpressionLength - the maximum length of a SpEL expression; must be a positive number
      Since:
      5.2.25
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize, int maximumExpressionLength, int maximumOperations)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for complete configuration control and the ability to override global defaults per use case.

      Parameters:
      compilerMode - the compiler mode that parsers using this configuration should use; must not be null
      compilerClassLoader - the ClassLoader to use as the basis for expression compilation; or null to use the default ClassLoader
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      maximumAutoGrowSize - the maximum size to which a collection can auto grow
      maximumExpressionLength - the maximum length of a SpEL expression; must be a positive number
      maximumOperations - the maximum number of operations permitted during SpEL expression evaluation; must be a positive number
      Since:
      6.2.19
      See Also:
    • SpelParserConfiguration

      public SpelParserConfiguration(SpelCompilerMode compilerMode, @Nullable ClassLoader compilerClassLoader, boolean autoGrowNullReferences, boolean autoGrowCollections, int maximumAutoGrowSize, int maximumExpressionLength, int maximumOperations, int maximumBigPowerBits)
      Create a new SpelParserConfiguration instance.

      NOTE: Favor builder() for a more readable way to override global defaults per use case.

      Parameters:
      compilerMode - the compiler mode that parsers using this configuration should use; must not be null
      compilerClassLoader - the ClassLoader to use as the basis for expression compilation; or null to use the default ClassLoader
      autoGrowNullReferences - if null references should automatically grow
      autoGrowCollections - if collections should automatically grow
      maximumAutoGrowSize - the maximum size to which a collection can auto grow
      maximumExpressionLength - the maximum length of a SpEL expression; must be a positive number
      maximumOperations - the maximum number of operations permitted during SpEL expression evaluation; must be a positive number
      maximumBigPowerBits - the maximum number of bits permitted in the result of a BigDecimal or BigInteger power operation; must be a positive number; use Integer.MAX_VALUE for no limit
      Since:
      7.0.9
  • Method Details

    • withDefaults

      public static SpelParserConfiguration withDefaults()
      Create a new SpelParserConfiguration instance with the same defaults applied by builder().

      This is shorthand for SpelParserConfiguration.builder().build(), for use whenever none of the defaults need to be overridden.

      Since:
      7.0.10
      See Also:
    • builder

      public static SpelParserConfiguration.Builder builder()
      Create a new SpelParserConfiguration.Builder for configuring a SpelParserConfiguration.

      The builder only requires configuration of the properties that need to deviate from their sensible defaults. See SpelParserConfiguration.Builder for details on those defaults.

      Since:
      7.0.10
      See Also:
    • getCompilerMode

      public SpelCompilerMode getCompilerMode()
      Return the compiler mode for parsers using this configuration object.
    • getCompilerClassLoader

      public @Nullable ClassLoader getCompilerClassLoader()
      Return the ClassLoader to use as the basis for expression compilation.
    • isAutoGrowNullReferences

      public boolean isAutoGrowNullReferences()
      Return true if null references should be automatically grown.
    • isAutoGrowCollections

      public boolean isAutoGrowCollections()
      Return true if collections should be automatically grown.
    • getMaximumAutoGrowSize

      public int getMaximumAutoGrowSize()
      Return the maximum size to which a collection can auto grow.
    • getMaximumExpressionLength

      public int getMaximumExpressionLength()
      Return the maximum number of characters that a SpEL expression can contain.
      Since:
      5.2.25
    • getMaximumOperations

      public int getMaximumOperations()
      Return the maximum number of operations permitted during SpEL expression evaluation.
      Since:
      6.2.19
    • getMaximumBigPowerBits

      public int getMaximumBigPowerBits()
      Return the maximum number of bits permitted in the result of a BigDecimal or BigInteger power operation.
      Since:
      7.0.9