一、概述
Activiti相对Jbpm来说,与Spring整合更加完美,具体可见本文的详细介绍
二、开发环境的准备
1. Maven的环境任务,请参考第一篇 (Activiti入门篇—Maven的环境准备)
2. Activiti的Eclipse插件安装
插件更新地址:http://activiti.org/designer/update/
<ignore_js_op>
安装完成后,可以设计一请假的流程,如下所示:
<ignore_js_op>
右键holidayRequest.bpmn文件,用Xml Editor打开,可以看到其生成的XML文件格式:
<ignore_js_op>
3. 安装数据库Mysql(略)
创建一数据库名为activiti,暂时不放表
三、Activiti与Spring的整合
1. 新建Maven项目
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
2. 加入依赖包
<ignore_js_op>
依赖的pom.xml文件如下所示:
- <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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.hotent.demo</groupId>
- <artifactId>activiti</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <dependencies>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-engine</artifactId>
- <version>5.15.1</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-spring</artifactId>
- <version>5.15.1</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.29</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>3.2.2.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.2.5</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.6</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-model</artifactId>
- <version>5.15.1</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-converter</artifactId>
- <version>5.15.1</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-process-validation</artifactId>
- <version>5.15.1</version>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>2.1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- <version>1.7.6</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.6</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- </dependency>
- </dependencies>
- </project>
【说明】:
在增加Activiti的包时,可以参考Activiti本身的依赖包的管理,当执行BaseTestCase发现缺少包时,可以从该文件找到对应的依赖包及其版本的要求。
<ignore_js_op>
3. 增加Spring中的Activiti配置文件
- <?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 id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
- <property name="username" value="root" />
- <property name="password" value="000" />
- <property name="defaultAutoCommit" value="false" />
- </bean>
- <bean id="processEngineConfiguration"
- class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
- <property name="dataSource" ref="dataSource" />
- <property name="databaseType" value="mysql"/>
- <property name="databaseSchemaUpdate" value="true" />
- <property name="jobExecutorActivate" value="false" />
- </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="managementService" factory-bean="processEngine" factory-method="getManagementService" />
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- </beans>
4. 编写TestCase
其代码如下:
- package com.hotent.test;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.transaction.TransactionConfiguration;
- import org.springframework.transaction.annotation.Transactional;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration({"classpath:spring-activiti.xml"})
- @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false)
- @Transactional
- public class BaseTestCase extends AbstractTransactionalJUnit4SpringContextTests{
- @Test
- public void test(){
- System.out.println ("test");
- }
- }
执行以上TestCase,若控制台输出test则表示已经成功整合了Activiti与Spring,并且可以登录数据库中查看其已经创建好Activiti对应的表,如下图所示:
<ignore_js_op>
5. 发布测试的流程示例
- package com.hotent.test.bpm;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.List;
- import javax.annotation.Resource;
- import org.activiti.engine.RepositoryService;
- import org.activiti.engine.RuntimeService;
- import org.activiti.engine.TaskService;
- import org.activiti.engine.repository.Deployment;
- import org.activiti.engine.repository.ProcessDefinition;
- import org.activiti.engine.task.Task;
- import org.junit.Assert;
- import org.junit.Test;
- import com.hotent.test.BaseTestCase;
- public class BpmDefinitionTest extends BaseTestCase{
- @Resource
- private RepositoryService repositoryService;
- @Resource
- private RuntimeService runtimeService;
- @Resource
- TaskService taskService;
- @Test
- public void testDeploy() throws IOException{
- InputStream is=readXmlFile();
- Assert.assertNotNull(is);
- //发布流程
- Deployment deployment=repositoryService.createDeployment().addInputStream("bpmn20.xml", is).name("holidayRequest").deploy();
- Assert.assertNotNull(deployment);
- System.out.println("deployId:" + deployment.getId());
- //查询流程定义
- ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
- Long businessKey=new Double(1000000*Math.random()).longValue();
- //启动流程
- runtimeService.startProcessInstanceById(processDefinition.getId(),businessKey.toString());
- //查询任务实例
- List<Task> taskList=taskService.createTaskQuery().processDefinitionId(processDefinition.getId()).list();
- Assert.assertNotNull(taskList==null);
- Assert.assertTrue(taskList.size()>0);
- for(Task task:taskList){
- System.out.println("task name is " + task.getName() + " ,task key is " + task.getTaskDefinitionKey());
- }
- }
- public InputStream readXmlFile() throws IOException{
- String filePath="holidayRequest.bpmn";
- return Class.class.getClass().getResource("/"+filePath).openStream();
- }
- }
执行结果如下所示:
<ignore_js_op>
相关推荐
activiti-spring-boot-starter-basic-6.0.0适配springboot2.1.2
activiti-spring-boot-starter-7.1.0.M1
本示例项目"activityexample"便是将Activiti API与Spring进行集成的一个实例,通过解压缩文件"activiti-api-spring-integration-example.zip",我们可以深入学习如何在Spring环境中运用Activiti。 首先,让我们理解...
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-engine-5.21.0.jar; 赠送原API文档:activiti-engine-5.21.0-javadoc.jar; 赠送源代码:activiti-engine-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-engine-5.21.0.pom; 包含...
赠送jar包:activiti-json-converter-5.21.0.jar; 赠送原API文档:activiti-json-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-json-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
赠送jar包:activiti-common-rest-5.21.0.jar; 赠送原API文档:activiti-common-rest-5.21.0-javadoc.jar; 赠送源代码:activiti-common-rest-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-common-rest-...
赠送jar包:activiti-bpmn-model-5.21.0.jar; 赠送原API文档:activiti-bpmn-model-5.21.0-javadoc.jar; 赠送源代码:activiti-bpmn-model-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-bpmn-model-...
赠送jar包:activiti-spring-5.21.0.jar; 赠送原API文档:activiti-spring-5.21.0-javadoc.jar; 赠送源代码:activiti-spring-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-spring-5.21.0.pom; 包含...
赠送jar包:activiti-image-generator-5.21.0.jar; 赠送原API文档:activiti-image-generator-5.21.0-javadoc.jar; 赠送源代码:activiti-image-generator-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
activiti-bpmn-converter-5.18.0-sources.jar
在"activiti-engine-5.6 与 spring集成"这个主题中,我们主要讨论以下几个关键知识点: 1. **Activiti Engine**: Activiti Engine 是 Activiti 的核心组件,负责执行流程定义,管理流程实例,以及处理与流程相关的...
赠送jar包:activiti-process-validation-5.21.0.jar; 赠送原API文档:activiti-process-validation-5.21.0-javadoc.jar; 赠送源代码:activiti-process-validation-5.21.0-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:activiti-bpmn-converter-5.21.0.jar; 赠送原API文档:activiti-bpmn-converter-5.21.0-javadoc.jar; 赠送源代码:activiti-bpmn-converter-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-...
本文将详细介绍如何在SpringBoot项目中整合Activiti,并通过提供的"springboot-activiti-test-master.zip"压缩包进行实战演练。 首先,我们需要了解SpringBoot与Activiti的基本概念。SpringBoot旨在简化Spring应用...
activiti-bpmn-converter-5.16.4.jar
赠送jar包:activiti-spring-5.21.0.jar; 赠送原API文档:activiti-spring-5.21.0-javadoc.jar; 赠送源代码:activiti-spring-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-spring-5.21.0.pom; 包含...
本篇将围绕“activiti-spring-examples”这个压缩包中的示例,深入探讨如何在Spring环境中配置和使用Activiti。 首先,我们要理解Activiti的核心概念。Activiti设计了流程定义(Process Definition)和流程实例...
1、将以下四个文件(见附件Activiti Designer 5.18.1插件补丁)拷贝到自己的eclipse的plugin文件夹下面,重启eclipse ...2、将activiti-designer-5.18.0文件夹copy到eclipse\dropins目录下; 3、重启eclipse即可