2017.2.20 activiti实战--第二章--搭建Activiti开发环境及简单示例(一)搭建开发环境

学习资料:《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。

 1     <!-- activiti -->
 2     <dependency>  
 3       <groupId>org.activiti</groupId>  
 4       <artifactId>activiti-engine</artifactId>  
 5       <version>${activiti.version}</version>  
 6     </dependency>
 7     
 8     <!-- activiti+spring -->
 9     <dependency>
10           <groupId>org.activiti</groupId>
11           <artifactId>activiti-spring</artifactId>
12           <version>${activiti.version}</version>  
13       </dependency>
14     
15     <!-- activiti-modeler -->
16     <dependency>
17         <groupId>org.activiti</groupId>
18         <artifactId>activiti-modeler</artifactId>
19             <version>${activiti.version}</version>
20     </dependency>

 

2.4 完整的配置文件示例

(1)单独模式 activiti.cfg.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://www.springframework.org/schema/beans
 4                 http://www.springframework.org/schema/beans/spring-beans.xsd">
 5 
 6     <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
 7         <property name="jdbcUrl" value="jdbc:h2:file:~/activiti-in-action-chapter7;AUTO_SERVER=TRUE" />
 8         <property name="jdbcDriver" value="org.h2.Driver" />
 9         <property name="jdbcUsername" value="sa" />
10         <property name="jdbcPassword" value="" />
11 
12         <property name="databaseSchemaUpdate" value="true" />
13         <property name="jobExecutorActivate" value="false" />
14     </bean>
23 </beans>

 

(2)与spring集成 applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
 3     xmlns:tx="http://www.springframework.org/schema/tx" 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                          http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.1.xsd
 6                            http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
 7     <!-- spring其他的配置略 -->
12 
13     <!-- 数据源 -->
14     <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
15         <property name="driverClass" value="org.h2.Driver" />
16         <property name="url" value="jdbc:h2:file:~/activiti-in-action-chapter7;AUTO_SERVER=TRUE" />
17         <property name="username" value="sa" />
18         <property name="password" value="" />
19     </bean>
20 
44     <!-- Activiti引擎配置 -->
45     <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
46         <property name="processEngineName" value="spring"></property>
47         <property name="dataSource" ref="dataSource" />
48         <property name="transactionManager" ref="transactionManager" />
49         <property name="databaseSchemaUpdate" value="true" />
50         <property name="jobExecutorActivate" value="false" />
51         <property name="deploymentResources" value="classpath*:/chapter7/leave.zip"></property>
52     </bean>
53 
54     <!-- Activiti引擎工厂 -->
55     <bean id="processEngineFactory" class="org.activiti.spring.ProcessEngineFactoryBean">
56         <property name="processEngineConfiguration" ref="processEngineConfiguration" />
57     </bean>
58 
59     <!-- Activiti的Service -->
60     <bean id="repositoryService" factory-bean="processEngineFactory" factory-method="getRepositoryService" />
61     <bean id="runtimeService" factory-bean="processEngineFactory" factory-method="getRuntimeService" />
62     <bean id="formService" factory-bean="processEngineFactory" factory-method="getFormService" />
63     <bean id="identityService" factory-bean="processEngineFactory" factory-method="getIdentityService" />
64     <bean id="taskService" factory-bean="processEngineFactory" factory-method="getTaskService" />
65     <bean id="historyService" factory-bean="processEngineFactory" factory-method="getHistoryService" />
66     <bean id="managementService" factory-bean="processEngineFactory" factory-method="getManagementService" />
67 
68 </beans>

 

posted @ 2017-02-20 15:44  七月流火嗞嗞嗞  阅读(13014)  评论(0编辑  收藏  举报