Rule Registry
The SpringRuleRegistry is a registry backed by the Spring application context. Instead of maintaining its own internal collection, it delegates directly to ListableBeanFactory — your rules are Spring beans, and the registry queries them as such.
Injecting the Registry
Section titled “Injecting the Registry”The registry is auto-configured and available for injection:
@Servicepublic class RuleExecutionService {
private final RuleRegistry registry; private final RuleContextOptions ruleContextOptions;
@Autowired public RuleExecutionService(RuleRegistry registry, RuleContextOptions ruleContextOptions) { this.registry = registry; this.ruleContextOptions = ruleContextOptions; }
public void executeByName(String ruleName) { // Preferred: run through a RuleFlow; the registry lookup happens at execution time RuleFlow<RuleContext> flow = RuleFlow.builder() .name("ExecuteByNameFlow") .run(ruleName) .build(); flow.run(RuleContext.builder().with(ruleContextOptions).build()); }}Looking Up Rules
Section titled “Looking Up Rules”You can retrieve a rule by its name (the bean name assigned during scanning):
// Get a rule by nameRule rule = registry.get("CreditCheckRule");
// Get with a specific typeRule rule = registry.get("CreditCheckRule", Rule.class);Listing All Rules
Section titled “Listing All Rules”// All registered rulesList<Rule> rules = registry.getRules();
// All registered rulesetsList<RuleSet> ruleSets = registry.getRuleSets();
// All registered ruleflows (new in 2.0.0)RuleFlow<?> flow = registry.getRuleFlow("CheckoutFlow");List<RuleFlow<?>> flows = registry.getRuleFlows();
// Sorted bean names of every Runnable bean (new in 2.1.0)Set<String> names = registry.getNames();
// Check if a name is already registeredboolean exists = registry.isNameInUse("CreditCheckRule");
// Total count of runnable beansint count = registry.getCount();Registry API Reference
Section titled “Registry API Reference”| Method | Returns | Description |
|---|---|---|
| get(name) | T | Retrieve a rule/ruleset by bean name |
| get(name, type) | T | Retrieve with type safety |
| getRules() | List<Rule> | All Rule beans in the context |
| getRuleSets() | List<RuleSet> | All RuleSet beans in the context |
| getRuleFlow(name) | RuleFlow<?> | Retrieve a RuleFlow bean by name (new in 2.0.0) |
| getRuleFlows() | List<RuleFlow<?>> | All RuleFlow beans in the context (new in 2.0.0) |
| getNames() | Set<String> | Sorted bean names of every Runnable bean, including ancestor bean factories (new in 2.1.0) |
| isNameInUse(name) | boolean | Check if a bean name exists |
| getCount() | int | Total Runnable bean count |
Context Shutdown
Section titled “Context Shutdown”Like SpringObjectFactory, the registry releases its reference to the ListableBeanFactory when its container shuts down. Since 2.1.0 both are DisposableBeans that release from their own container’s destroy callback (previously a ContextClosedEvent listener), so closing a child context no longer shuts down the parent’s registry. Any call to the registry after shutdown throws an UnrulyException with a clear message: “Application Context is closed.”