Skip to content

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.

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.

  • Auto-Configuration All core beans configured out of the box. Override any of them with your own.
  • Rule Scanning Annotate your app with @RuleScan and rules are discovered automatically.
  • Dependency Injection Constructor-inject Spring beans directly into your @Rule classes.
  • Spring Converters Your existing Spring Converter beans 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.executorService pool 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.validation constraints run as rulii rules. The application’s Validator bean is rulii’s, in place of Hibernate Validator, and @Validate names are bean names. See Bean Validation in Spring Boot (new in 2.2.0, opt-in since 2.3.0).
@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.

@Rule
public 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.