1、安装插件

在idea里面,activiti的插件叫actiBPM,在插件库里面把它安装好,重启idea就行了。

2、新建一个maven项目,并更改pom.xml。pom中依赖如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6.  
  7. <groupId>helloActiviti</groupId>
  8. <artifactId>helloActiviti</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10.  
  11. <dependencies>
  12. <dependency>
  13. <groupId>org.activiti</groupId>
  14. <artifactId>activiti-spring</artifactId>
  15. <version>5.18.0</version>
  16. </dependency>
  17. <!--JUnit测试-->
  18. <dependency>
  19. <groupId>junit</groupId>
  20. <artifactId>junit</artifactId>
  21. <version>4.12</version>
  22. </dependency>
  23. <!--activiti-->
  24. <dependency>
  25. <groupId>org.activiti</groupId>
  26. <artifactId>activiti-engine</artifactId>
  27. <version>5.18.0</version>
  28. <exclusions>
  29. <exclusion>
  30. <artifactId>slf4j-api</artifactId>
  31. <groupId>org.slf4j</groupId>
  32. </exclusion>
  33. <exclusion>
  34. <artifactId>spring-beans</artifactId>
  35. <groupId>org.springframework</groupId>
  36. </exclusion>
  37. <exclusion>
  38. <artifactId>jackson-core-asl</artifactId>
  39. <groupId>org.codehaus.jackson</groupId>
  40. </exclusion>
  41. <exclusion>
  42. <artifactId>commons-lang3</artifactId>
  43. <groupId>org.apache.commons</groupId>
  44. </exclusion>
  45. <exclusion>
  46. <artifactId>commons-lang3</artifactId>
  47. <groupId>org.apache.commons</groupId>
  48. </exclusion>
  49. </exclusions>
  50. </dependency>
  51. <!--MySQL 驱动包,如果是其他库的话需要换驱动包-->
  52. <dependency>
  53. <groupId>mysql</groupId>
  54. <artifactId>mysql-connector-java</artifactId>
  55. <version>5.1.35</version>
  56. </dependency>
  57. </dependencies>
  58. </project>

3、在src/main/resources下面新建一个BPMN文件

新建之后页面会变成如下图所示这样,中间是画布,右边是一些元素,左边是每个元素的一些详细信息,直接拖拽右边的元素就可以画流程了。

通过拖拽,完成简单的流程(这里只用到了StartEvent、UserTask、EndEvent),连接线需要悬停在对应元素上通过拖拽中心点来产生。

画完流程图之后要更改对应元素的name和assignee,我这里画的一个很简单的流程图,只用到了startEvent、endEvent和userTask。

接下来,创建一个Activiti类,在这里我直接和Test一起做了。同时,写好activiti的配置文件activiti.cfg.xml(PS:在写数据库连接的时候,要先创建对应的数据库和用户,数据库最好是新的,因为activiti会创建出24张它自己的表)。
目录结构:

activiti.cfg.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  5.  
  6. <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
  7. <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
  8. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useUnicode=true&amp;characterEncoding=utf8"></property>
  9. <property name="jdbcUsername" value="root"></property>
  10. <property name="jdbcPassword" value="root"></property>
  11. <property name="databaseSchemaUpdate" value="true"></property>
  12. </bean>
  13.  
  14. </beans>

测试类:

  1. import org.activiti.engine.*;
  2. import org.activiti.engine.repository.DeploymentBuilder;
  3. import org.junit.Test;
  4. import org.activiti.engine.task.Task;
  5.  
  6. import java.util.List;
  7.  
  8. public class ActivitiTest {
  9. /**
  10. * 会默认按照Resources目录下的activiti.cfg.xml创建流程引擎
  11. */
  12. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  13.  
  14. @Test
  15. public void test() { //以下两种方式选择一种创建引擎方式:1.配置写在程序里 2.读对应的配置文件
  16. //
  17. testCreateProcessEngine();
  18. //
  19. testCreateProcessEngineByCfgXml();
  20. deployProcess();
  21. startProcess();
  22. queryTask();
  23. //handleTask();
  24. }
  25.  
  26. /**
  27. * 测试activiti环境
  28. */
  29. @Test
  30. public void testCreateProcessEngine() {
  31. ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
  32. cfg.setJdbcDriver("com.mysql.jdbc.Driver");
  33. cfg.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/activiti");
  34. cfg.setJdbcUsername("root");
  35. cfg.setJdbcPassword("root"); //配置建表策略
  36. cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
  37. ProcessEngine engine = cfg.buildProcessEngine();
  38. }
  39.  
  40. /**
  41. * 根据配置文件activiti.cfg.xml创建ProcessEngine
  42. */
  43. @Test
  44. public void testCreateProcessEngineByCfgXml() {
  45. ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
  46. ProcessEngine engine = cfg.buildProcessEngine();
  47. }
  48.  
  49. /**
  50. * 发布流程
  51. * RepositoryService
  52. */
  53. @Test
  54. public void deployProcess() {
  55. RepositoryService repositoryService = processEngine.getRepositoryService();
  56. DeploymentBuilder builder = repositoryService.createDeployment();
  57. builder.addClasspathResource("hello.bpmn");
  58. builder.deploy();
  59. }
  60.  
  61. /**
  62. * 启动流程
  63. * <p>
  64. * RuntimeService
  65. */
  66. @Test
  67. public void startProcess() {
  68. RuntimeService runtimeService = processEngine.getRuntimeService();
  69. //可根据id、key、message启动流程
  70. runtimeService.startProcessInstanceByKey("myProcess_1");
  71. }
  72.  
  73. /**
  74. * 查看任务
  75. * TaskService
  76. */
  77. @Test
  78. public void queryTask() {
  79. TaskService taskService = processEngine.getTaskService(); //根据assignee(代理人)查询任务
  80. String assignee = "emp";
  81. List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee).list();
  82. int size = tasks.size();
  83. for (int i = 0; i < size; i++) {
  84. Task task = tasks.get(i);
  85. }
  86. for (Task task : tasks) {
  87. System.out.println("taskId:" + task.getId() + ",taskName:" + task.getName() + ",assignee:" + task.getAssignee() + ",createTime:" + task.getCreateTime());
  88. }
  89. }
  90.  
  91. /**
  92. * 办理任务
  93. */
  94. @Test
  95. public void handleTask() {
  96. TaskService taskService = processEngine.getTaskService(); //根据上一步生成的taskId执行任务
  97. String taskId = "2504";
  98. taskService.complete(taskId);
  99. }
  100.  
  101. }

启动流程之后就会有相应的任务产生,存在act_ru_task表中,可以查看任务节点

使用idea进行activiti工作流开发入门学习的更多相关文章

  1. 【转载】salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建

    salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建   VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的 ...

  2. 【转载】salesforce 零基础开发入门学习(五)异步进程介绍与数据批处理Batchable

    salesforce 零基础开发入门学习(五)异步进程介绍与数据批处理Batchable   本篇知识参考:https://developer.salesforce.com/trailhead/for ...

  3. 【转载】salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解   建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schem ...

  4. 【转载】salesforce 零基础开发入门学习(三)sObject简单介绍以及简单DML操作(SOQL)

    salesforce 零基础开发入门学习(三)sObject简单介绍以及简单DML操作(SOQL)   salesforce中对于数据库操作和JAVA等语言对于数据库操作是有一定区别的.salesfo ...

  5. 【转载】salesforce 零基础开发入门学习(二)变量基础知识,集合,表达式,流程控制语句

    salesforce 零基础开发入门学习(二)变量基础知识,集合,表达式,流程控制语句 salesforce如果简单的说可以大概分成两个部分:Apex,VisualForce Page. 其中Apex ...

  6. 【转载】salesforce 零基础开发入门学习(一)Salesforce功能介绍,IDE配置以及资源下载

    salesforce 零基础开发入门学习(一)Salesforce功能介绍,IDE配置以及资源下载   目前国内已经有很多公司做salesforce,但是国内相关的资料确是少之又少.上个月末跳槽去了新 ...

  7. Web开发入门学习笔记

    公司web项目终于要启动了,本以为django学习可以在实战中进行,结果最终使用了Drupal框架,好吧,那我们就PHP走起,买了本<细说PHP>,先跟着过一遍Web开发入门. HTTP协 ...

  8. salesforce 零基础开发入门学习(三)sObject简单介绍以及简单DML操作(SOQL)

    salesforce中对于数据库操作和JAVA等语言对于数据库操作是有一定区别的.salesforce中的数据库使用的是Force.com 平台的数据库,数据表一行数据可以理解成一个sObject变量 ...

  9. salesforce 零基础开发入门学习(一)Salesforce功能介绍,IDE配置以及资源下载

    目前国内已经有很多公司做salesforce,但是国内相关的资料确是少之又少.上个月末跳槽去了新公司,主要做的就是salesforce,不过当时想要看一些相关资料确实比较难.为了避免想要零基础学习的人 ...

随机推荐

  1. 【Zookeeper】集群环境搭建

    一.概述 1.1 Zookeeper的角色 1.2 Zookeeper的读写机制 1.3 Zookeeper的保证 1.4 Zookeeper节点数据操作流程 二.Zookeeper 集群环境搭建 2 ...

  2. 《形式化分析工具Scyther性能研究》------摘抄整理

    本篇论文的主要创新点在--------使用 Scyther工具发现对部分 KCI攻击搜索出现漏报的现象,并给出了存在的原因, 介绍了 形式化分析工具   AVispa全称是   Automated V ...

  3. 机器学习 三剑客 之 pandas + numpy

    机器学习 什么是机器学习? 机器学习是从数据中自动分析获得规律(模型),并利用规律对未知数据进行预测 机器学习存在的目的和价值领域? 领域: 医疗.航空.教育.物流.电商 等... 目的: 让机器学习 ...

  4. 模拟一个http 请求的json格式报文,带 rsa 签名操作

    一.对需要加密的字符串,定义RsaSignUnsign 类,代码如下: 实现了: 1.实现了生成新的pubkey.pri_key方法: 2.将新生成的keys 写入文件: 3.从文件获取pubkey. ...

  5. java基础:多态过程中的动态绑定

    重刷java-core的chapter05,P158 重读多态,感觉又不一样了. 记录一下对象方法执行过程: 1.  编译器查看对象声明类型和方法名,如class.fuction(param),cla ...

  6. gitlab自动备份脚本auto_backup_to_remote

    !/bin/bash gitlab 服务器备份路径 LocalBackDir=/var/opt/gitlab/backups 远程备份服务器 gitlab备份文件存放路径 RemoteBackDir= ...

  7. python面向对象基础(四)内置方法 __xx__之new与init

    __init__和__new__方法 __new__() 是在新式类中新出现的方法,它作用在构造方法建造实例之前,可以这么理解,在 Python 中存在于类里面的构造方法 __init__() 负责将 ...

  8. django 重定向如何解决iframe页面嵌套问题

    出现问题背景:从登录页进入到首页后,如出现后台重启或者用户清除cookie,或者session过期,token验证等问题,会重定向到登录页.由于使用的是iframe,出现登录页面嵌套在首页框架下.很是 ...

  9. HDU-1160-FatMouse's Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

  10. pyinstaller打包程序包含openpyxl库问题解决

    带有openpyxl库时,直接打包,总会失败: 原因:看本地文件...Anaconda3\Lib\site-packages\PyInstaller\hooks\hook-openpyxl.py 发现 ...