Introduction
rulii-spring is the official Spring Boot integration for the rulii rule engine. It brings auto-configuration, dependency injection, component scanning, and Spring-native type conversion to your rules — so you can focus on business logic instead of wiring.
Why rulii-spring?
Section titled “Why rulii-spring?”The core rulii library is intentionally zero-dependency. That’s great for portability, but when you’re already running a Spring Boot application you want your rules to participate in the same ecosystem: injecting services, reading configuration from application.properties, sharing converters, and being discoverable through component scanning.
rulii-spring bridges that gap with a single dependency.
Key Features
Section titled “Key Features”- Auto-Configuration All core beans configured out of the box. Override any of them with your own.
- Rule Scanning Annotate your app with
@RuleScanand rules are discovered automatically. - Dependency Injection Constructor-inject Spring beans directly into your
@Ruleclasses. - Spring Converters Your existing Spring
Converterbeans work inside rules. - Externalized Messages Rule violation messages can live in
application.properties. - Bean-Backed Registry Look up rules, rulesets, and ruleflows by name through the Spring context.
- XML Rules & RuleFlows Declare rules, rulesets, and full RuleFlow pipelines in Spring XML. Each artifact records its file and line, category, and tags for explorer tooling (new in 2.1.0).
- Async Executor A managed
rulii.executorServicepool powers async flows (new in 2.0.0), with lifecycle-safe shutdown that drains running and queued rules on context close (new in 2.1.0). - Bean Validation With rulii-bean-validation added, your
jakarta.validationconstraints run as rulii rules. The application’sValidatorbean is rulii’s, in place of Hibernate Validator, and@Validatenames are bean names. See Bean Validation in Spring Boot (new in 2.2.0, opt-in since 2.3.0).
A Quick Look
Section titled “A Quick Look”@SpringBootApplication@RuleScan(scanBasePackages = "com.example.rules")public class MyApp {
public static void main(String[] args) { SpringApplication.run(MyApp.class, args); }}That’s all the setup you need. Spring Boot auto-configures the rule engine, scans for your @Rule classes, and registers them as Spring beans with full dependency injection.
@Rulepublic class EligibilityRule {
private final EligibilityService service;
@Autowired public EligibilityRule(EligibilityService service) { this.service = service; }
@Given public boolean isEligible(String customerId) { return service.checkEligibility(customerId); }
@Then public void approve(String customerId) { service.approve(customerId); }}The EligibilityService is injected by Spring, and the rule is available by name from the RuleRegistry. The rest of this guide covers every feature in detail.