00 — Getting Started

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?

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

Auto-Configuration

Nine 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 and rulesets by name through the Spring context.

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.

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