/**PageBeginHtml Block Begin **/ /***自定义返回顶部小火箭***/ /*生成博客目录的JS 开始*/ /*生成博客目录的JS 结束*/

Activiti6 示例1--部署流程、启动流程、查询第一个流程节点、查询第二个流程节点等信息

 

Activiti6 示例1--部署流程、启动流程、查询第一个流程节点、查询第二个流程节点等信息

 

一、项目代码框架

image

 

该eclipse 版本为2017年版本的,配置工作流插件 请参考《Eclipse 下 Activiti Designer 插件安装教程

 

 

 

image

 

二:项目代码:

package com.alan.activiti6Demo.fristAct;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

public class FirstAct {


	public static void main(String[] args) throws Exception {
		//创建引擎,这步骤会进行数据库表的创建或者更新操作
		ProcessEngine engine=ProcessEngines.getDefaultProcessEngine();
		//部署流程文件至 数据库表中。
		RepositoryService rs=engine.getRepositoryService();//资源服务
		RuntimeService  rts = engine.getRuntimeService();//运行时服务
		TaskService ts=engine.getTaskService();//流程任务处理服务
		/*
		 * 一次部署,可以包含多个文件:流程图、流程定义文件
		 * 部署的文件信息放入在act_ge_bytearray 中
		 * 部署记录信息 放入在act_re_deployment 中
		 */
		rs.createDeployment().addClasspathResource("first.bpmn").deploy();
		ProcessInstance pi=rts.startProcessInstanceByKey("myProcess");//每启动流程一次,则可以获取一个流程实例对象。流程定义文件可以启动多次

		// 查询第一个任务
		Task task = ts.createTaskQuery().singleResult();
		System.out.println("第一个任务完成前,当前任务名称:" + task.getName());
		// 完成第一个任务
		ts.complete(task.getId());
		// 查询第二个任务
		task = ts.createTaskQuery().singleResult();
		System.out.println("第二个任务完成前,当前任务名称:" + task.getName());
		// 完成第二个任务(流程结束)
		ts.complete(task.getId());
		task = ts.createTaskQuery().singleResult();
		engine.close();//关闭引擎
		System.exit(0);//退出
	}



}

activiti.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
	<!-- 流程引擎配置的bean -->
	<bean id="processEngineConfiguration"
		class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
		<!--  <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/activiti6demo" />-->
		<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/activiti6act" />
		<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUsername" value="root" />
		<property name="jdbcPassword" value="123456" />
		<property name="databaseSchemaUpdate" value="true" />
	</bean>
</beans>

 

first.bpmn

image

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="Write Vaction"></userTask>
    <userTask id="usertask2" name="Audit"></userTask>
    <sequenceFlow id="flow1" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="470.0" y="130.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="1160.0" y="130.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="650.0" y="120.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="940.0" y="120.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="1045.0" y="147.0"></omgdi:waypoint>
        <omgdi:waypoint x="1160.0" y="147.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="755.0" y="147.0"></omgdi:waypoint>
        <omgdi:waypoint x="940.0" y="147.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="505.0" y="147.0"></omgdi:waypoint>
        <omgdi:waypoint x="650.0" y="147.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

 

log4j.properties

log4j.rootLogger=INFO, stdout

# Console Appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n

# Custom tweaks
log4j.logger.com.codahale.metrics=WARN
log4j.logger.com.ryantenney=WARN
log4j.logger.com.zaxxer=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.engine.internal=WARN
log4j.logger.org.hibernate.validator=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.springframework.web=WARN
log4j.logger.org.springframework.security=WARN

 

LIb 文件查看此群文件

image

image

 

执行结果

11:55:11,544 [main] INFO  org.activiti.engine.ProcessEngines  - Initializing process engine using configuration 'file:/E:/softCode/activiti6/activitiDemo_firstAct/bin/activiti.cfg.xml'
11:55:11,546 [main] INFO  org.activiti.engine.ProcessEngines  - initializing process engine for resource file:/E:/softCode/activiti6/activitiDemo_firstAct/bin/activiti.cfg.xml
11:55:12,607 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Found 1 auto-discoverable Process Engine Configurators
11:55:12,608 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Found 1 Process Engine Configurators in total:
11:55:12,608 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - class org.activiti.management.jmx.JMXConfigurator (priority:10000)
11:55:12,608 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Executing beforeInit() of class org.activiti.management.jmx.JMXConfigurator (priority:10000)
Sun Jun 02 23:55:12 CST 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
11:55:15,553 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Found compatibility handler instance : class org.activiti.compatibility.DefaultActiviti5CompatibilityHandler
11:55:15,554 [main] INFO  org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Executing configure() of class org.activiti.management.jmx.JMXConfigurator (priority:10000)
11:55:15,868 [jmxConnectorStarterThread] INFO  org.activiti.management.jmx.DefaultManagementAgent  - JMX Connector thread started and listening at: service:jmx:rmi:///jndi/rmi://RuiLian-PC:1099/jmxrmi/activiti
11:55:15,893 [main] INFO  org.activiti.engine.impl.ProcessEngineImpl  - ProcessEngine default created
11:55:15,905 [main] INFO  org.activiti.engine.ProcessEngines  - initialised process engine default
第一个任务完成前,当前任务名称:Write Vaction
第二个任务完成前,当前任务名称:Audit

 

 

 

数据库

image

 

数据库表执行上述代码,自动生成

 

 

 

 

 

 


posted @ 2024-06-03 00:05  一品堂.技术学习笔记  阅读(91)  评论(0编辑  收藏  举报