Auto-Configuration
rulii-spring ships with one central @AutoConfiguration class — RuleConfig — that sets up everything you need. It’s registered through Spring Boot’s META-INF/spring/AutoConfiguration.imports file, so it activates automatically when the library is on the classpath. More auto-configurations sit beside it for Bean Validation: BeanValidationConfig and HibernateValidatorConfig (since 2.2.0, the second under the name BeanValidationOptOutConfig) decide the application’s Bean Validation provider once rulii-bean-validation is added, and JpaValidationConfig (since 2.3.0) keeps JPA on Hibernate Validator (covered at the end of this page).
How It Works
Section titled “How It Works”Every bean defined by RuleConfig is annotated with @ConditionalOnMissingBean. This means you can override any bean by declaring your own — Spring Boot will skip the default and use yours instead.
Auto-Configured Beans
Section titled “Auto-Configured Beans”RuleConfig creates the core beans below, plus four new beans in 2.0.0 (covered afterwards). Here’s each one, what it does, and how to replace it.
1. BindingMatchingStrategy
Section titled “1. BindingMatchingStrategy”Controls how rule parameters are matched to bindings at runtime. The default uses the standard matching strategy.
@Bean@ConditionalOnMissingBean(BindingMatchingStrategy.class)public BindingMatchingStrategy bindingMatchingStrategy() { return BindingMatchingStrategy.builder().build();}2. ParameterResolver
Section titled “2. ParameterResolver”Resolves method parameters when invoking rule conditions and actions.
@Bean@ConditionalOnMissingBean(ParameterResolver.class)public ParameterResolver parameterResolver() { return ParameterResolver.builder().build();}3. MessageResolver
Section titled “3. MessageResolver”Resolves messages for rule violations from Spring’s Environment. This is a Spring-specific implementation that reads message codes from application.properties.
@Bean@ConditionalOnMissingBean(MessageResolver.class)public MessageResolver messageResolver(Environment environment) { return new SpringEnvironmentMessageResolver(environment);}4. MessageFormatter
Section titled “4. MessageFormatter”Formats resolved message strings, substituting placeholders with runtime values.
@Bean@ConditionalOnMissingBean(MessageFormatter.class)public MessageFormatter messageFormatter() { return MessageFormatter.builder().build();}5. ObjectFactory
Section titled “5. ObjectFactory”Creates rule instances. When Spring’s AutowireCapableBeanFactory is available, this uses SpringObjectFactory to enable constructor injection. Otherwise falls back to rulii’s default factory.
@Bean(name = BeanNames.OBJECT_FACTORY_NAME)@ConditionalOnMissingBean(ObjectFactory.class)public ObjectFactory objectFactory(BeanFactory beanFactory) { if (beanFactory instanceof AutowireCapableBeanFactory ctx) { return new SpringObjectFactory(ctx); } return ObjectFactory.builder().build();}6. ConverterRegistry
Section titled “6. ConverterRegistry”Manages type converters for rule parameters. Automatically picks up any Spring Converter beans and wraps Spring’s ConversionService with a SpringConverterAdapter.
@Bean(name = BeanNames.SPRING_CONVERTER_REGISTRY)@ConditionalOnMissingBean(ConverterRegistry.class)public ConverterRegistry converterRegistry( @Autowired(required = false) Set<Converter<?, ?>> converters, @Autowired(required = false) ConversionService conversionService, @Value("${rulii.converts.registerDefaults:true}") boolean registerDefaults) { // Registers defaults, custom converters, and Spring ConversionService}7. RuleRegistry
Section titled “7. RuleRegistry”A Spring-backed registry that looks up rules directly from the application context. Uses SpringRuleRegistry when a ListableBeanFactory is available.
@Bean(BeanNames.RULE_REGISTRY)@ConditionalOnMissingBean(RuleRegistry.class)public RuleRegistry ruleRegistry( @Autowired(required = false) ListableBeanFactory ctx) { if (ctx != null) return new SpringRuleRegistry(ctx); return RuleRegistry.builder().build();}8. RuleContextOptions
Section titled “8. RuleContextOptions”Bundles all the above beans into a single options object for rule execution. Includes a fixed thread pool for async execution and the system clock.
@Bean@ConditionalOnMissingBean(RuleContextOptions.class)public RuleContextOptions ruleContextOptions(...) { return new SpringEnabledRuleContextOptions( matchingStrategy, parameterResolver, messageFormatter, converterRegistry, objectFactory, messageResolver, Executors.newFixedThreadPool(Math.max(2, Runtime.getRuntime().availableProcessors())), Clock.systemDefaultZone(), Locale.getDefault());}9. RuleBeanDefinitionRegistryPostProcessor
Section titled “9. RuleBeanDefinitionRegistryPostProcessor”A fallback post-processor that automatically scans for rules when @RuleScan is not present. It uses AutoConfigurationPackages to determine the base packages. This bean is only created if no RuleRegistrarMetaInfo bean exists (which @RuleScan registers).
New Beans in 2.0.0
Section titled “New Beans in 2.0.0”rulii.executorService
Section titled “rulii.executorService”A bounded thread pool (work queue of 1000, caller-runs policy) used for async rule and RuleFlow execution, shut down with the application context. It is overridden by name: define your own bean named rulii.executorService to replace it — unrelated ExecutorService beans are deliberately ignored.
Tracer
Section titled “Tracer”Auto-configured with every RuliiListener, RuleListener, RuleSetListener, and RuleFlowListener bean found in the context. A bean that implements several listener interfaces is registered exactly once.
ScriptProcessorManager & ScriptTextResolverConfigurer
Section titled “ScriptProcessorManager & ScriptTextResolverConfigurer”The script manager wires all discovered ScriptProcessorFactory beans (including SpEL). The resolver configurer enables ${property:default} environment placeholders inside script text; disable it with rulii.scripts.resolvePlaceholders=false.
What Changed in 2.1.0
Section titled “What Changed in 2.1.0”rulii.executorService Is Now a RuleExecutorService
Section titled “rulii.executorService Is Now a RuleExecutorService”The rulii.executorService bean is now a RuleExecutorService — the same fixed size, bounded queue of 1000, and caller-runs policy as before, with threads named rulii-exec-N. On context close it stops accepting new work, waits up to rulii.executor.awaitTerminationSeconds (default 10) for running and queued rules to finish, then interrupts what is left. It is still overridden by name: define your own bean named rulii.executorService to replace it.
ScriptProcessorFactoryRegistration
Section titled “ScriptProcessorFactoryRegistration”A new bean that registers every ScriptProcessorFactory bean with the JVM-wide ScriptProcessorManager and takes them out again on context destroy, through rulii 2.1’s ScriptProcessorManager.unregister. Removal is by identity — a factory a newer context has since registered under the same language is left alone — and names this context had displaced fall back to service-loader discovery. Replaceable with your own bean.
Lifecycle Fix for Child Contexts
Section titled “Lifecycle Fix for Child Contexts”SpringRuleRegistry and SpringObjectFactory are now DisposableBeans that release their bean factory from their own container’s destroy callback. Closing a child context (Spring Cloud bootstrap, SpringApplicationBuilder.child(), @ContextHierarchy) no longer shuts down the parent’s rule infrastructure.
Bean Validation (2.2.0, opt-in since 2.3.0)
Section titled “Bean Validation (2.2.0, opt-in since 2.3.0)”BeanValidationConfig
Section titled “BeanValidationConfig”rulii-bean-validation is an optional dependency of rulii-spring. Add it and rulii-spring makes it the application’s Bean Validation provider; without it this configuration does nothing. (In 2.2.0 the library came with rulii-spring and was on by default.) The auto-configuration org.rulii.spring.validation.BeanValidationConfig runs before Spring Boot’s ValidationAutoConfiguration and defines the defaultValidator bean Boot would otherwise define: a LocalValidatorFactoryBean pinned to RuliiValidationProvider. The provider is therefore selected whatever the classpath order — the Jakarta bootstrap otherwise takes the first provider it finds, and Boot’s validation starter brings Hibernate Validator. rulii-bean-validation is not a certified implementation; its known differences are on the specification coverage page.
The provider’s RuliiConfiguration receives the Spring RuleRegistry (so a @Validate name is a bean name), the Spring RuleContextOptions, every ConstraintMapper and ValueExtractor bean, and the property rulii.validation.failFast. Boot’s ValidationConfigurationCustomizer beans are applied after that, and Boot’s method validation post-processor validates through this bean, so @Validated services work unchanged. The unwrapped BeanValidator is a bean too, for code that wants validateIn or the materialized rule flows.
@AutoConfiguration(beforeName = "...ValidationAutoConfiguration")@ConditionalOnClass(name = {"...ValidationConfigurationCustomizer", "org.rulii.validation.beans.BeanValidator"})@ConditionalOnProperty(name = "rulii.validation.enabled", havingValue = "true", matchIfMissing = true)public class BeanValidationConfig {
@Bean(name = "defaultValidator") @ConditionalOnMissingBean(Validator.class) public static LocalValidatorFactoryBean defaultValidator(...) { // LocalValidatorFactoryBean pinned to RuliiValidationProvider, // configured with the Spring RuleRegistry, RuleContextOptions, // ConstraintMapper / ValueExtractor beans and rulii.validation.failFast }
@Bean @ConditionalOnMissingBean(BeanValidator.class) public BeanValidator beanValidator(Validator validator) { return validator.unwrap(BeanValidator.class); }}It is conditional on rulii-bean-validation and Boot’s validation module being present (spring-boot-validation, which spring-boot-starter-validation brings) and on rulii.validation.enabled not being false. As with every other bean here, your own Validator bean takes precedence. Setting rulii.validation.enabled=true without the dependency does nothing and logs a warning at startup.
HibernateValidatorConfig
Section titled “HibernateValidatorConfig”Set rulii.validation.enabled=false to keep Hibernate Validator while rulii-bean-validation is on the classpath. Because both providers are then present, HibernateValidatorConfig (named BeanValidationOptOutConfig in 2.2.0) runs in place of BeanValidationConfig and, when Hibernate Validator is present, defines the defaultValidator bean pinned to HibernateValidator, with Boot’s message interpolator and the ValidationConfigurationCustomizer beans applied — the opt-out is deterministic, and the application gets exactly what it had before. Without Hibernate Validator on the classpath the bean is left to Boot, which bootstraps the one provider there is (rulii’s) without the Spring rulii wiring.
JpaValidationConfig (new in 2.3.0)
Section titled “JpaValidationConfig (new in 2.3.0)”Spring Boot does not hand its Validator to JPA: Hibernate bootstraps Bean Validation on its own and takes the first provider on the classpath. With rulii-bean-validation added beside Hibernate Validator that would depend on the order of the dependencies. JpaValidationConfig takes the chance out of it: while both providers are on the classpath it hands JPA the factory Hibernate would have built with Hibernate Validator alone, whatever rulii.validation.enabled says. So JPA validates entities as it did before, and @Validate and @Expr on an entity are not checked at persist time; validate the entity through the Validator bean before saving it. An application that removes Hibernate Validator has one provider left, and JPA validates with rulii. A factory the application has already set for JPA is left alone.
Default Scripting Language from the Environment
Section titled “Default Scripting Language from the Environment”The ScriptProcessorManager bean now reads rulii.script.defaultLanguage from the Spring Environment (so from application.properties) and calls setDefaultLanguage with it, exactly as rulii core reads the system property of the same name. @Expr constraints and script rules that name no language get it from configuration.
Overriding a Bean
Section titled “Overriding a Bean”To replace any auto-configured bean, just define your own. For example, to provide a custom MessageResolver:
@Configurationpublic class MyRuleConfig {
@Bean public MessageResolver messageResolver() { return new MyCustomMessageResolver(); }}Because RuleConfig uses @ConditionalOnMissingBean, your bean takes priority and the default is skipped entirely.