activiti5.10 入门详解

安装插件

 Help -> Install New Software->add

插件下载地址:http://activiti.org/designer/update/

 

 

 

新建java project(这里不重复过程,本文中工程名activiti-project

 

下载官方demo

(下在官方demo是为了使用demo中的jar包,不用单独找了。通过每次报错补充相互依赖的jar包相当麻烦)

 

1、地址:http://activiti.org/downloads/activiti-5.10.zip

解压后activiti-5.10\workspace为官方的所有demo,其中我们需要使用activiti-spring-examples工程中libs-runtimelibs-test中的所有jar,在此我们定义user library

2、定义user library

eclipse选中刚才建好的java project然后alt + enter ->java build path -> libraries ->add libraries

 

 

选择User library-> next -> User library -> new -> 输入labrary名称

 

 

之后选中mylib -> add external jars -> 选择activiti-spring-examples工程中libs-runtimelibs-test中的所有jar

添加工作流

2、添加工作流:File ->new ->other

 

选择Next然后选择你存放bpmn文件的工程的package下(本例在cn.mjl.config包下,src/main/javaclasspath

 

 

spring配置工作流(本例使用demo中自带h2数据库)

配置dataSource

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">

    <property name="driverClass" value="org.h2.Driver" />

    <property name="url" value="jdbc:h2:file:~/activiti;AUTO_SERVER=TRUE" />

    <property name="username" value="sa" />

    <property name="password" value="" />

  </bean>

配置事务

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

    <property name="dataSource" ref="dataSource" />

  </bean>

 

  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

    <property name="dataSource" ref="dataSource" />

    <property name="transactionManager" ref="transactionManager" />

    <property name="databaseSchemaUpdate" value="true" />

    <property name="jobExecutorActivate" value="false" />

    <property name="deploymentResources" value="classpath*:/cn/mjl/config/MyProcess.bpmn" /> //启动spring会自动将bpmn文件导入到数据库。改变bpmn文件后会在数据库中产生新的版本

  </bean>

主要的bean

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">

    <property name="processEngineConfiguration" ref="processEngineConfiguration" />

  </bean>

 

  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />

  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />

  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />

  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />

  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />

  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

工作流的使用

<!--[if !supportLists]-->1、  <!--[endif]-->bpmn文件上鼠标右击 -> Open with ->activiti Diagram Edit 

<!--[if !supportLists]-->2、  <!--[endif]-->右侧空间栏选择工作流控件,直接脱取。

<!--[if !supportLists]-->3、  <!--[endif]-->启动工作流

ProcessInstance processInstance = runtimeService

                      .startProcessInstanceByKey("p1"); key一般是指bpmn文件中的idId一般指数据库中对应的数据Id

<!--[if !supportLists]-->4、<!--[endif]-->获取任务

List<Task> tasks = taskService.createTaskQuery()                  .taskAssignee(userString).orderByTaskCreateTime().desc().list();

<!--[if !supportLists]-->5、<!--[endif]-->完成任务

      Task leaveTask = tasks.get(0);

Map<String, Object> varlueMap = new HashMap<String, Object>();

           varlueMap.put("deleteOrderResult", deleteOrderResult);

           taskService.complete(leaveTask.getId(), varlueMap);

complete:完成任务,第一个参数接受任务id,第二个参数接受为HashMaplist

 

 

最后说一句,详细文档和demo已经上传到csdn上,上面有图有说明,而且已经解决了导出图片乱码的问题

地址:http://download.csdn.net/detail/luckymjl2/4749760

我也是资源分匮乏,没办法了,需要的去下吧

 

猜你喜欢

转载自luckymjl2.iteye.com/blog/1721671
今日推荐