SpEL Scripting
rulii-spring 1.2.0 adds first-class support for Spring Expression Language (SpEL) as a scripting language inside rules. SpEL expressions are compiled, cached, and evaluated against the current RuleContext bindings. No extra configuration is required — the integration is wired automatically by auto-configuration.
How It Works
Section titled “How It Works”rulii-spring registers a SpelScriptProcessor under the language name "el". When a script with that language name is evaluated, the processor:
- Compiles the expression string using Spring’s
ExpressionParser(compiled expressions are cached for reuse) - Creates a
StandardEvaluationContextwith aBindingAccessorthat bridges ruliiBindingsinto SpEL’s property resolution - Evaluates the expression and returns the result
Writing SpEL Scripts
Section titled “Writing SpEL Scripts”All RuleContext bindings are exposed as a single SpEL variable named #ctx. Access any binding through it using standard SpEL property syntax. The # prefix is the standard SpEL notation for variables registered on the evaluation context.
// Check a binding value"#ctx.age >= 18"
// String comparison"#ctx.country == 'US'"
// Arithmetic and method calls"#ctx.price * #ctx.quantity > 1000""#ctx.name.toUpperCase() == 'ALICE'"
// Conditional expression"#ctx.score >= 90 ? 'A' : #ctx.score >= 80 ? 'B' : 'C'"Using SpEL in Rules (Java API)
Section titled “Using SpEL in Rules (Java API)”// Create a SpEL-backed condition using Script.builder() with language "el"Script<Boolean> spelScript = Script.builder().build("el", "#ctx.age >= 18 and #ctx.country == 'US'");Condition condition = Condition.builder().build(spelScript);
// Build the ruleRule rule = Rule.builder() .with("EligibilityRule") .given(condition) .then(Action.builder().build(Script.builder().build("el", "#ctx.status = 'approved'"))) .build();For XML-based rule declaration with SpEL expressions, see XML Rule Definitions and XML RuleFlows. The default expression language for the XML namespace is "el" (SpEL).
Auto-Configuration
Section titled “Auto-Configuration”RuleConfig automatically creates a SpelScriptProcessorFactory bean and wires a ScriptProcessorRegistry into SpringEnabledRuleContextOptions. Every RuleContext created through the standard factory has SpEL available out of the box.
Since 2.1.0, ScriptProcessorFactory beans are registered with the JVM-wide ScriptProcessorManager by a ScriptProcessorFactoryRegistration bean and unregistered when the context closes, so a closed context is no longer reachable from the process-wide registry — which matters for test suites, DevTools restarts, and redeploys.
What’s New in 2.2.0
Section titled “What’s New in 2.2.0”“el” Is Still SpEL; Jakarta EL Is “jakarta-el”
Section titled ““el” Is Still SpEL; Jakarta EL Is “jakarta-el””rulii core 2.2.0 adds Jakarta Expression Language as a scripting language of its own, registered as jakarta-el (alias jel). The plain el name stays what rulii-spring registers under it — SpEL — so XML rules and flows declared with language="el" keep their meaning. Pick jakarta-el explicitly when you want Jakarta EL (as in @Expr constraints). From rulii 2.3.0 it can be written as #{...} or ${...}: Jakarta EL scripts are left out of property placeholder resolution, so a ${property} placeholder inside one is not resolved (on 2.2.0 ${...} was read as a placeholder and failed). It needs an EL implementation such as Expressly on the classpath. See the core Scripting Support page for the engine.
Default Language from application.properties
Section titled “Default Language from application.properties”The ScriptProcessorManager bean reads rulii.script.defaultLanguage from the Spring Environment, as rulii core reads the system property of the same name. It is the language a script is compiled in when none is named — Script.builder().build(text) and @Expr constraints without lang — and it is never inferred from the classpath. This is separate from the XML namespace’s file-level default language, which remains el.
rulii.script.defaultLanguage=jakarta-el