(一)搭建开发环境
学习资料:《Activiti实战》
第一章 认识Activiti
2.1 下载Activiti
官网:http://activiti.org/download.html
入下载页后,可以看到最新版本的压缩包、快速入门、用户手册、javadoc等。我下载的时候,最新版本是activiti-5.22.0.zip。
目录结构:
database:
包含了activiti表的创建、删除及版本升级三种类型的脚本。
创建和删除脚本的命名规则:activiti.[oracle|postgres|db2|mssql|mysql|h2|hsql].[create|drop].[identity|engine|history].sql
版本升级脚本的命名规则:activiti.oracle.upgradestep.[5x].to.[5(x+1)].history
docs:
包含了javadocs、用户手册和xsd。用户手册包含了环境配置,十分钟快速入门,各模块使用教程。xsd中包含与流程定义相关的scheme。
libs:略。
war:略。
2.2 环境配置
jdk、maven、intellij。
2.3 配置文件介绍
2.3.1 activiti.cfg.xml
(1)processEngineConfiguration
activiti可以单独使用,也可以与spring集成,所以配置文件有所区别。
单独模式:
与spring集成:
(2)database
activiti支持的数据库类型:
不论是单独模式,还是与spring集成,database都可以有如下配置方式。
jdbc方式(spring集成时也类似,不再重复):
dataSource方式(spring集成时也类似,不再重复):
2.3.2 pom.xml
如果不与spring集成,只需要activiti-engine。
如果需要与spring集成,需要加上activiti-spring。其中spring的配置此处略。
如果需要使用activiti的modeler,需要加上activiti-modeler。
<!-- activiti --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${activiti.version}</version> </dependency> <!-- activiti+spring --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${activiti.version}</version> </dependency> <!-- activiti-modeler --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-modeler</artifactId> <version>${activiti.version}</version> </dependency>
2.4 完整的配置文件示例
(1)单独模式 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 id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:h2:file:~/activiti-in-action-chapter7;AUTO_SERVER=TRUE" /> <property name="jdbcDriver" value="org.h2.Driver" /> <property name="jdbcUsername" value="sa" /> <property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> <property name="jobExecutorActivate" value="false" /> </bean> </beans>
补充下mysql的
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" /> <property name="jdbcDriver" value="com.mysql.jdbc.Driver" /> <property name="jdbcUsername" value="root" /> <property name="jdbcPassword" value="123456" />
(2)与spring集成 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!-- spring其他的配置略 --> <!-- 数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="org.h2.Driver" /> <property name="url" value="jdbc:h2:file:~/activiti-in-action-chapter7;AUTO_SERVER=TRUE" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> <!-- Activiti引擎配置 --> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="processEngineName" value="spring"></property> <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*:/chapter7/leave.zip"></property> </bean> <!-- Activiti引擎工厂 --> <bean id="processEngineFactory" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <!-- Activiti的Service --> <bean id="repositoryService" factory-bean="processEngineFactory" factory-method="getRepositoryService" /> <bean id="runtimeService" factory-bean="processEngineFactory" factory-method="getRuntimeService" /> <bean id="formService" factory-bean="processEngineFactory" factory-method="getFormService" /> <bean id="identityService" factory-bean="processEngineFactory" factory-method="getIdentityService" /> <bean id="taskService" factory-bean="processEngineFactory" factory-method="getTaskService" /> <bean id="historyService" factory-bean="processEngineFactory" factory-method="getHistoryService" /> <bean id="managementService" factory-bean="processEngineFactory" factory-method="getManagementService" /> </beans>