Backend Development 15 min read

Integrating URule Rule Engine into Java Projects: Installation, Configuration, and Sample Code

This article explains the background, features, installation steps, core concepts, library definitions, rule set creation (wizard and script), decision tables, practical usage scenarios, and provides complete Java and configuration code examples for integrating the URule rule engine in a Spring Boot backend application.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Integrating URule Rule Engine into Java Projects: Installation, Configuration, and Sample Code

The article begins with a background describing the need for a flexible rule engine during a project refactor and introduces URule as a browser‑based, open‑source solution that runs on multiple operating systems.

It then outlines URule's main features in a comparison table between the PRO and open‑source editions, highlighting capabilities such as wizard‑style decision sets, script decision sets, decision trees, decision flows, decision tables, and various advanced functions.

Installation and usage are covered next. Four deployment modes are mentioned (embedded, local, distributed, and standalone), and the guide focuses on the open‑source version integrated with Spring Boot. The required database configuration is shown:

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 UI can be accessed at http://localhost:8090/urule/frame .

Basic concepts introduce the two main components of URule: the designer (library files) and the execution engine. Four library types are described:

Variable library – maps Java POJOs 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.

Example of a variable library class:

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

Action library methods are annotated with @ExposeAction (or @ActionId ) to be callable from rules. Sample action class:

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

Rule sets are created either as wizard‑style (visual drag‑and‑drop) or script‑style (written scripts). The wizard style consists of three parts: if (condition), then (action), and else (alternative action). A simple example rule set image is referenced.

For script‑style rule sets, the same principles apply but the rules are defined in code.

Decision tables are presented as an alternative visual representation of rule sets, offering a clear matrix of conditions and outcomes.

Application scenario describes a user‑level promotion system where ordinary users, members, and elite members are promoted based on registration counts, order amounts, and order continuation rates. The scenario is modeled using a decision table.

The article concludes that rule engines are optional enhancements that help separate complex business logic from code, requiring solid understanding of requirements and abstraction.

Reference source code links are provided for further exploration.

backendJavarule engineconfigurationSpring BootURuleDecision Table
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

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.