Building a Visual Rule Engine with Spring Boot and URule

This article walks through the motivation, architecture, installation steps, core concepts, and practical usage of integrating the URule visual rule engine into a Spring Boot project, including library files, wizard and script rule sets, decision tables, and a real‑world promotion scenario.

Java Architect Handbook
Java Architect Handbook
Java Architect Handbook
Building a Visual Rule Engine with Spring Boot and URule

Background

During a project refactor, many conditional checks were needed, prompting an exploration of rule engines. While many mature engines exist, URule was chosen for its browser‑based visual configuration and cross‑platform support.

Introduction

A rule engine separates complex business logic from code, allowing the program to focus on core functionality while rules are defined externally. URule runs on Windows, Linux, and Unix, and offers both open‑source and Pro versions.

Installation and Usage

URule Pro provides four deployment modes, but this guide uses the open‑source version integrated with Spring Boot. The project structure includes a Spring Boot service with a MySQL datasource configured as follows:

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 starting the service, the URule UI is accessible at http://localhost:8090/urule/frame.

Basic Concepts

Overall Architecture

URule consists of two parts: the designer (library and rule files) and the execution engine.

Library Files

Four types of libraries are used:

Variable library – maps Java POJOs (e.g., Stu) to rule variables.

Constant library – stores enums or constant values.

Parameter library – a temporary Map for rule parameters.

Action library – exposes Spring beans and methods to rules via @ExposeAction.

Example of a POJO with @Label annotations used by the variable library:

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;
}

An action bean is defined as:

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("方法1")
    public boolean evalTest(String username) {
        if (username == null) return false;
        if (username.equals("张三")) return true;
        return false;
    }

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

    @ExposeAction("打印内容")
    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("打印Stu")
    public void printUser(Stu m) {
        System.out.println("Hello " + m.getName() + ", is age:" + m.getAge());
    }
}

Rule Sets

URule supports two rule set styles:

Wizard‑style rule set – visual point‑and‑click configuration.

Script‑style rule set – rules written as scripts, requiring coding knowledge.

Creating a wizard‑style rule set involves adding a decision set, importing library files, and configuring the If‑Then‑Else blocks directly in the UI.

Decision Table

A decision table presents the same logic as a rule set but in a tabular form, making it easier to read for non‑technical stakeholders.

Application Scenario

A real‑world use case is a membership promotion system where users can be ordinary, member, or elite member. Different promotion rules apply, such as registration counts and order amounts over a three‑month period. The scenario is modeled using a decision table that lists the conditions and the resulting promotion level.

Conclusion

Integrating URule provides a clean way to externalize complex business rules, making them maintainable and understandable. However, developers must still grasp the underlying requirements to model the rules correctly, which is an essential step in robust software design.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendJavaRule Enginespring-bootURuleVisual Configuration
Java Architect Handbook
Written by

Java Architect Handbook

Focused on Java interview questions and practical article sharing, covering algorithms, databases, Spring Boot, microservices, high concurrency, JVM, Docker containers, and ELK-related knowledge. Looking forward to progressing together with you.

0 followers
Reader feedback

How this landed with the community

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.