Installation & Setup
Requirements
Section titled “Requirements”- Java 17+ Required by rulii and by the Jakarta Validation 3.1 API.
- rulii 2.3.0 The core rule engine. Pulled in transitively.
- jakarta.validation 3.1 The Bean Validation API. Pulled in transitively.
Add rulii-bean-validation to your pom.xml. It brings in rulii core and jakarta.validation:jakarta.validation-api and nothing else.
<dependency> <groupId>org.rulii</groupId> <artifactId>rulii-bean-validation</artifactId> <version>1.1.0</version></dependency>Gradle
Section titled “Gradle”implementation 'org.rulii:rulii-bean-validation:1.1.0'Expression Language
Section titled “Expression Language”If a message uses Jakarta Expression Language (${...}), or an @Expr is written in it, add an EL implementation, exactly as with any other provider. Without one, EL in messages is left as written instead of failing.
<dependency> <groupId>org.glassfish.expressly</groupId> <artifactId>expressly</artifactId> <version>5.0.0</version></dependency>Any JSR-223 engine on the classpath (GraalJS, Groovy) is available to @Expr as well, under the names rulii registers for it. See Scripting Support for the engines rulii knows.
Spring Boot
Section titled “Spring Boot”Add this library beside rulii-spring 2.3.0 or later. Adding the dependency is the switch: with Spring Boot’s validation module on the classpath the application’s Validator bean is this library’s, wired into the Spring rulii context. (rulii-spring 2.2.0 brought the library in itself.) See Spring Boot Integration.
Verify Your Setup
Section titled “Verify Your Setup”With this library as the only provider on the classpath, the standard bootstrap hands out a rulii validator:
import jakarta.validation.Validation;import jakarta.validation.Validator;import jakarta.validation.constraints.NotNull;import org.rulii.validation.beans.BeanValidator;
public class QuickTest {
static class Greeting { @NotNull String text; }
public static void main(String[] args) { Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); System.out.println(validator.unwrap(BeanValidator.class)); System.out.println(validator.validate(new Greeting()).size()); // Output: 1 (text must not be null) }}