任何Java企业级应用可以分成三个部分 −

  • UI – 用户界面(前端)
  • 服务层连接到数据库
  • 业务层






  • 制作: 制作过程涉及创建规则文件(.DRL文件)。
  • 运行时: 它涉及到创建工作存储器和处理活化。


Drools is Rule Engine or a Production Rule System that uses the rule-based approach to implement and Expert System. Expert Systems are knowledge-based systems that use knowledge representation to process acquired knowledge into a knowledge base that can be used for reasoning.

A Production Rule System is Turing complete with a focus on knowledge representation to express propositional and first-order logic in a concise, non-ambiguous and declarative manner.

The brain of a Production Rules System is an Inference Engine that can scale to a large number of rules and facts. The Inference Engine matches facts and data against Production Rules – also called Productions or just Rules – to infer conclusions which result in actions.

A Production Rule is a two-part structure that uses first-order logic for reasoning over knowledge representation. A business rule engine is a software system that executes one or more business rules in a runtime production environment.

A Rule Engine allows you to define “What to Do” and not “How to do it.”

What is a Rule?

Rules are pieces of knowledge often expressed as, "When some conditions occur, then do some tasks."

    <Condition is true>
    <Take desired Action>

The most important part of a Rule is its when part. If the when part is satisfied, the thenpart is triggered.

rule  <rule_name>
      <attribute> <value>

Pattern Matching

The process of matching the new or existing facts against Production Rules is called Pattern Matching, which is performed by the Inference Engine. There are a number of algorithms used for Pattern Matching including:

  • Linear
  • Rete
  • Treat
  • Leaps

Drools Implements and extends the Rete Algorithm. The Drools Rete implementation is called ReteOO, signifying that Drools has an enhanced and optimized implementation of the Rete algorithm for object-oriented systems.

Advantages of a Rule Engine

Declarative Programming

Rules make it easy to express solutions to difficult problems and get the solutions verified as well. Unlike codes, Rules are written in less complex language; Business Analysts can easily read and verify a set of rules.

Logic and Data Separation

The data resides in the Domain Objects and the business logic resides in the Rules. Depending upon the kind of project, this kind of separation can be very advantageous.

Speed and Scalability

The Rete OO algorithm on which Drools is written is already a proven algorithm. With the help of Drools, your application becomes very scalable. If there are frequent change requests, one can add new rules without having to modify the existing rules.

Centralization of Knowledge

By using Rules, you create a repository of knowledge (a knowledge base) which is executable. It is a single point of truth for business policy. Ideally, Rules are so readable that they can also serve as documentation.

Tool Integration

Tools such as Eclipse provide ways to edit and manage rules and get immediate feedback, validation, and content assistance. Auditing and debugging tools are also available.

Drools教程 Drools 编程课程
1 Drools教程 Drools是一个业务逻辑集成平台(BLip)。它是用Java编写。它是由JBoss和红帽公司扩展支持,并实现Rete模式匹配算法的一个开源项目。
2 Drools Eclipse插件 下面是安装Drools插件的先决条件: Java 1.5 (以上) SE JDK Eclipse 4.2 (或以上版本)和Drools插件 由于Drools是用Java编写的一个BRMS(业务规则管理系统),我们将涵盖如何添加所需的插件本节。考
3 Drools运行时 Drools运行系统必须指示编辑器使用运行Drools jar特定版本的程序。可以运行程序/应用程序在不同的Drools运行时。 点击 Windows Preference Drools Installed Drools Runtime. 然后单击添加如下面的屏幕
4 创建Drools程序(入门) 要创建一个基本的Drools的程序,打开Eclipse。到 File New Project. 选择Drools项目。给一个合适的名称项目。例如,DroolsTest。 下一个屏幕会提示您选择想要在Drools项目中的一些文件。 选择第
5 Drools常用术语 规则 规则引擎的心脏,在其中指定条件(如果 a 那么 b). 概况 概况是其上的规则将在行动中的数据。从Java的角度来看,概况是POJO(普通Java对象)。 会话 在Drools中基于知识是会话的核心
6 Drools规则编写 如果有在看Hello World项目(Sample.drl)的默认规则,也有很多使用的关键字,我们现在将一个一个地来解释。 Sample.drl 包 : 每一个规则开始包的名称。包充当规则命名空间。包内的规则名
7 Drools规则语法 正如你看到的.drl(规则文件)都有自己的语法,让我们盖这个章介绍规则语法的某些部分。 在规则中的条件 规则可以包含很多的条件和模式,如: Account (balance == 200) Customer (name == V
8 Drools简单项目 在本章中,我们将创建一个Drools项目下列问题说明: 根据不同的城市和各类产品(城和产品的组合),找出当地税务相关的城市。 我们将有两个DRL文件为我们的Drools项目。这两个文件
9 Drools调试 有不同的方法来调试Drools项目。在这里,我们将编写一个实用工具类,知道哪些规则正在被触发或发射。 通过这种方法,可以检查所有的规则都在Drools项目得到触发。这里是我们的工具
  • Copyright © 2021 猿狮院, All rights reserved.