rule names : drools 文件中 规则名称 如下图:
package com.sample;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import com.cn.droolsac.User;
/**
*
* @Title: DroolsActiviti.java
* @Package com.sample
* @Description: 工作流整合规则引擎
* @author cc
* @date 2019年7月18日
* @version V1.0
*/
public class DroolsActiviti {
ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();
/**
*
* @param args
*/
public static void main(String[] args) {
}
@Test
public void getProcess() {
System.err.println("准备部署。。。。。");
Deployment deployment= processEngine.getRepositoryService()//获取流程部署对象相关的service
.createDeployment()//创建一个部署对象
.name("事故上报-规则引擎")//完成部署名称
.addClasspathResource("bpmn/drools.bpmn")
.addClasspathResource("rules/Samples.drl")
.deploy();//完成部署
System.err.println("部署完成。。。");
System.err.println("部署名称:"+deployment.getName());
System.err.println("部署id:"+deployment.getId());
}
@Test
public void startProcessInstance() {
String processDefinitionKey="myProcess";
Map<String, Object> map=new HashMap<String,Object>();
String businessKey="EtEmergencyinfo:1";
ProcessInstance poInstance= processEngine.getRuntimeService()
.startProcessInstanceByKey(processDefinitionKey,businessKey,map);
System.err.println("流程定义id:"+poInstance.getId());
System.err.println("流程定义名称:"+poInstance.getName());
System.err.println("流程实列Id:"+poInstance.getProcessDefinitionId());
}
@Test
public void taskCommpet() {
User user=new User();
user.setName("李四");
user.setPrice(100.00);
//使用key 会安装最新的版本
Map<String, Object> map=new HashMap<String,Object>();
//设置规则文件中 传入的参数
map.put("user",user);
String taskId="2504";
processEngine.getTaskService().complete(taskId,map);
System.err.println("任务完成");
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cn.drools</groupId>
<artifactId>Drools</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Drools Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<runtime.version>6.4.0.Final</runtime.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-test</artifactId>
<version>${runtime.version}</version>
</dependency>
<!--工作流-->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.21.0</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
<version>6.2.0.CR2</version>
</dependency>
</dependencies>
<build>
<finalName>Drools</finalName>
</build>
</project>
pom.xml
*activiti5.x 整合 drools 6.x 的时候会出现 找不到类 需要增加 jar 包 在pom 文件中 最后一个 *