activiti 流程文件存哪里_Activiti 部署流程等资源文件的四种方式

  • Post author:
  • Post category:其他


Activiti 的流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取。

一、Activiti流程资源

流程定义文件:文件扩展为*.bpmn20.xml或*.bpmn

流程定义的图片:用BPMN2.0规范的各种图形描绘,文件扩展为*.png

表单文件:把表单内容保存在一个文件中,文件扩展为*.form

规则文件:文件扩展为*.drl

二、部署资源文件

1.classpath方式

public class ProcessDefinitionTest {

/**流程引擎(核心对象),默认加载类路径下命名为activiti.cfg.xml*/

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

//部署流程定义

@Test

public void deployementProcessDefinition(){

Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.name(“helloworld演示”)//声明流程的名称

.addClasspathResource(“diagrams/helloworld.bpmn”)//加载资源文件,一次只能加载一个文件

.addClasspathResource(“diagrams/helloworld.png”)//

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

publicclassProcessDefinitionTest{

/**流程引擎(核心对象),默认加载类路径下命名为activiti.cfg.xml*/

ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();

//部署流程定义

@Test

publicvoiddeployementProcessDefinition(){

Deploymentdeployment=processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.name(“helloworld演示”)//声明流程的名称

.addClasspathResource(“diagrams/helloworld.bpmn”)//加载资源文件,一次只能加载一个文件

.addClasspathResource(“diagrams/helloworld.png”)//

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

}

2.InputStream方式

使用InputStream方式部署流程资源需要传入一个输入流及资源的名称,输入流的来源不限,可以从classpath读取,也可以从一个绝对路径文件读取,也可以是从网络上读取。

//Inputstream方式

@Test

public void deployementProcessDefinitionByInputStream() throws FileNotFoundException{

//获取资源相对路径

String bpmnPath = “diagrams/helloworld.bpmn”;

String pngPath = “diagrams/helloworld.png”;

//读取资源作为一个输入流

FileInputStream bpmnfileInputStream = new FileInputStream(bpmnPath);

FileInputStream pngfileInputStream = new FileInputStream(pngPath);

Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addInputStream(“helloworld.bpmn”,bpmnfileInputStream)

.addInputStream(“helloworld.png”, pngfileInputStream)

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

//Inputstream方式

@Test

publicvoiddeployementProcessDefinitionByInputStream()throwsFileNotFoundException{

//获取资源相对路径

StringbpmnPath=”diagrams/helloworld.bpmn”;

StringpngPath=”diagrams/helloworld.png”;

//读取资源作为一个输入流

FileInputStreambpmnfileInputStream=newFileInputStream(bpmnPath);

FileInputStreampngfileInputStream=newFileInputStream(pngPath);

Deploymentdeployment=processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addInputStream(“helloworld.bpmn”,bpmnfileInputStream)

.addInputStream(“helloworld.png”,pngfileInputStream)

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

3.字符串方式

利用字符串方式可以直接传入纯文本作为资源的来源,和前两种方式类似,字符串方式的实现原理是把一组字符串的内容转化为字节流后再部署。

//字符串方式

@Test

public void deployementProcessDefinitionByString() throws FileNotFoundException{

//字符串

String text = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>…”;

Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addString(“helloworld.bpmn”,text)

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

1

2

3

4

5

6

7

8

9

10

11

12

13

//字符串方式

@Test

publicvoiddeployementProcessDefinitionByString()throwsFileNotFoundException{

//字符串

Stringtext=”<?xmlversion =\”1.0\”encoding=\”UTF-8\”?>…”;

Deploymentdeployment=processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addString(“helloworld.bpmn”,text)

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

4.zip/bar格式压缩包方式

以上3种部署方式一次只能部署一个资源,除非执行多次deployment.addXxx()方法,如何一次部署多个资源呢?很简单,是我们可以使用zip/bar格式压缩包方式。将资源文件手动或使用Ant脚本,打包文件扩展名可以是Activiti官方推荐的bar或普通的zip。

//部署流程定义(zip)

@Test

public void deployementProcessDefinitionByzip(){

//从classpath路径下读取资源文件

InputStream in = this.getClass().getClassLoader().getResourceAsStream(“diagrams/helloworld.zip”);

ZipInputStream zipInputStream = new ZipInputStream(in);

Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addZipInputStream(zipInputStream)//使用zip方式部署,将helloworld.bpmn和helloworld.png压缩成zip格式的文件

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

1

2

3

4

5

6

7

8

9

10

11

12

13

//部署流程定义(zip)

@Test

publicvoiddeployementProcessDefinitionByzip(){

//从classpath路径下读取资源文件

InputStreamin=this.getClass().getClassLoader().getResourceAsStream(“diagrams/helloworld.zip”);

ZipInputStreamzipInputStream=newZipInputStream(in);

Deploymentdeployment=processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service

.createDeployment()//创建部署对象

.addZipInputStream(zipInputStream)//使用zip方式部署,将helloworld.bpmn和helloworld.png压缩成zip格式的文件

.deploy();//完成部署

System.out.println(“部署ID:”+deployment.getId());//1

System.out.println(“部署时间:”+deployment.getDeploymentTime());

}

浏览量:

114

0



版权声明:本文为weixin_29467373原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。