Backend Development 15 min read

Integrating URule Rule Engine with Spring Boot: Installation, Configuration, and Usage

This article introduces the URule rule engine, explains how to install and configure its open‑source version with Spring Boot, describes its core concepts such as variable, constant, parameter, and action libraries, and demonstrates rule set and decision table creation for real‑world business scenarios.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Integrating URule Rule Engine with Spring Boot: Installation, Configuration, and Usage

1. Introduction

Rule engine is a component that can be embedded in programs to separate complex decision logic from business code, taking input data and producing output based on predefined rules.

Many mature engines exist (Drools, Aviator, EasyRules), but URule offers a browser‑based visual editor and runs on various operating systems.

URule has open‑source and Pro versions; the following table (omitted) shows the differences.

2. Installation and Usage

URule Pro can be used in four modes: embedded, local, distributed, and standalone service. This article focuses on the open‑source version integrated with Spring Boot.

Project modules are shown (image omitted). Create an empty database, configure datasource in spring.datasource.* properties, and start the service; the database tables are created automatically.

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/urule-data?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=mysql

After startup, open http://localhost:8090/urule/frame in a browser to access the visual rule editor.

3. Core Concepts

3.1 Overall Architecture

URule consists of a designer (library files and rule files) and a rule execution engine. The designer includes variable, parameter, constant, and action libraries.

3.2 Library Files

Variable Library

Maps Java POJOs (e.g., DTO, VO) to variables usable in rules. Variables are created via the UI; names can be Chinese or English.

package com.cicada;

import com.bstek.urule.model.Label;
import lombok.Data;

@Data
public class Stu {
    @Label("姓名")
    private String name;
    @Label("年龄")
    private int age;
    @Label("班级")
    private String classes;
}

The @Label annotation links POJO fields to variable titles.

Constant Library

Represents Java constants or enums, such as gender or organization codes.

Parameter Library

Provides temporary variables (a Map) that can be defined at runtime.

Action Library

Maps Spring beans and their methods to actions callable from rules. Methods are annotated with @ExposeAction .

package com.bstek.urule.cicada;

import com.bstek.urule.action.ActionId;
import com.bstek.urule.model.ExposeAction;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component("action")
public class Action {
    @ActionId("Hello")
    public String hello() {
        return "hello";
    }

    @ExposeAction(value="方法1")
    public boolean evalTest(String username) {
        if (username == null) return false;
        else if (username.equals("张三")) return true;
        return false;
    }

    @ExposeAction(value="测试Int")
    public int testInt(int a, int b) {
        return a + b;
    }

    @ExposeAction(value="打印内容")
    public void printContent(String username, Date birthday) {
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (birthday != null) {
            System.out.println(username + "今年已经" + sd.format(birthday) + "岁了!");
        } else {
            System.out.println("Hello " + username);
        }
    }

    @ExposeAction(value="打印Stu")
    public void printUser(Stu m) {
        System.out.println("Hello " + m.getName() + ", is age:" + m.getAge());
    }
}

3.3 Rule Sets

Rule sets combine conditions (if), actions (then), and optional else branches. URule supports wizard‑style (visual) and script‑style rule sets.

Wizard‑style Rule Set

Created via “Decision Set → Add Wizard Decision Set”. Libraries are imported, then rules are configured through the UI.

Script‑style Rule Set

Written as scripts; not covered in detail.

3.4 Decision Tables

Alternative tabular representation of rule sets; more intuitive for non‑technical stakeholders.

4. Application Scenario

Example: user promotion logic based on registration counts, order amounts, and order continuity, with separate rules for normal → member and member → elite member promotions.

5. Conclusion

Rule engines can decouple complex business logic from code, making maintenance easier, though they require solid understanding of requirements and proper abstraction.

Javarule engineBackend DevelopmentSpring BootURuleDecision Table
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.