1, Activiti官网:http://www.activiti.org/  主页可以看到jar包的下载.

2, 进入http://www.activiti.org/userguide/index.html 用户指导页进行学习研究.

3, 在maven中引入activiti jar 文件的

To include the activiti engine in your project, add following dependency (note that you need to change the version to the latest release):

<dependency>
  <groupId>org.activiti</groupId>
  <artifactId>activiti-engine</artifactId>
  <version>5.x</version>
</dependency>
      

And if you use Activiti with the Spring integration, then your dependencies could look like this:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>spring.version</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>spring.version</version>
</dependency>

4, 如果不使用maven,可以在下载的zip包的libs文件夹中看到所有的jar文件(包括源文件jar)必须的依赖包

org.activiti:activiti-engine:jar:5.12.1+- org.apache.commons:commons-email:jar:1.2:compile|  +- javax.mail:mail:jar:1.4.1:compile|  \- javax.activation:activation:jar:1.1:compile+- commons-lang:commons-lang:jar:2.4:compile+- org.mybatis:mybatis:jar:3.1.1:compile+- org.springframework:spring-beans:jar:3.1.2.RELEASE:compile|  \- org.springframework:spring-core:jar:3.1.2.RELEASE:compile|     +- org.springframework:spring-asm:jar:3.1.2.RELEASE:compile|     \- commons-logging:commons-logging:jar:1.1.1:compile\- joda-time:joda-time:jar:2.1:compile  

Note: the mail jars are only needed if you are using the mail service task

得到ProcessEngine对象是很容易的,会去classpath中找 activiti.cfg.xml文件.
ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
<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">      <propertyname="jdbcUrl"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>    <propertyname="jdbcDriver"value="org.h2.Driver"/>    <propertyname="jdbcUsername"value="sa"/>    <propertyname="jdbcPassword"value=""/>        <propertyname="databaseSchemaUpdate"value="true"/>        <propertyname="jobExecutorActivate"value="false"/>        <propertyname="mailServerHost"value="mail.my-corp.com"/>     <propertyname="mailServerPort"value="5025"/>      </bean>

</beans>

5  这是一个基于Spring的xml文件,但是并不意味着它只能在spring中配置

ProcessEngineConfiguration 对象可以使用配置文件创建也可以指定自己的bean名称,如

ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource,String beanName);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream,String beanName);

所有ProcessEngineConfiguration.createXXX() 方法返回ProcessEngineConfiguration对象,再调用buildProcessEngine()方法即可返回ProcessEngine 对象。

 activiti.cfg.xml 必须有一个bean的id为  'processEngineConfiguration'.,这个bean是用来构造ProcessEngine的

<bean id="processEngineConfiguration"

class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> ,class可以指定的类

  • org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration: the process engine is used in a standalone way. Activiti will take care of the transactions. By default, the database will only be checked when the engine boots (and an exception is thrown if there is no Activiti schema or the schema version is incorrect).

  • org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration: this is a convenience class for unit testing purposes. Activiti will take care of the transactions. An H2 in-memory database is used by default. The database will be created and dropped when the engine boots and shuts down. When using this, probably no additional configuration is needed (except when using for example the job executor or mail capabilities).

  • org.activiti.spring.SpringProcessEngineConfiguration:To be used when the process engine is used in a Spring environment. See the Spring integration section for more information.

  • org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: To be used when the engine runs in standalone mode, with JTA transactions.

有两种方式配置Activiti引擎用到的数据库,第一种是jdbc方式

<propertyname="jdbcUrl"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/><propertyname="jdbcDriver"value="org.h2.Driver"/><propertyname="jdbcUsername"value="sa"/><propertyname="jdbcPassword"value=""/>

The data source that is constructed based on the provided JDBC properties will have the default MyBatis connection pool settings. The following attributes can optionally be set to tweak that connection pool (taken from the MyBatis documentation):

基于JDBC属性构造数据源的方式默认使用Mybatis连接池设置,下面属性可以设置调整连接池
  • jdbcMaxActiveConnections: 最大活动连接数. Default is 10.

  •  jdbcMaxIdleConnections:  空闲连接数

  • jdbcMaxCheckoutTime: 一个连接在返回之前被检查的时间 . Default is 20000 (20 seconds).

  • jdbcMaxWaitTime: 这是一个低级设置,一般都是默认不修改 Default is 20000 (20 seconds).


<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="activiti"/>  <property name="password"value="activiti"/>  <property name="defaultAutoCommit"value="false"/></bean>      

<bean id="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">      <propertyname="dataSource"ref="dataSource"/>
...>
必须确保数据源的依赖库在classpath中下面属性也应该被设置,无论是jdbc还是data source databaseType: 数据库类型  ,可能的取值 {h2, mysql, oracle, postgres, mssql, db2}

    databaseSchemaUpdate:  流程引擎启动关闭时数据库的策略.

false 默认:检查数据库schema版本,在流程引擎创建或抛异常时

           true 在部署流程引擎时,检查数据库schema,不存在就创建           create-drop 在流程引擎创建时创建数据库schema,关闭时删除数据库schema

在 activiti-5.13/database下可以看到可以看到具体的sql dll文件


  • engine: 引擎执行必须的表. Required.

  • identity:  这些表包含用户,组,用户在组中的身份,是可选的 这些表应该被使用当使用默认的身份管理引擎的装载.

  • history: 包含历史和审计信息. 可选的,当历史级别设置为none时是不需要的

Activiti数据库都以ACT_开头 .

ACT_RE_*:  'RE' stands for repository. Tables with this prefix contain 'static' information such as process definitions and process resources (images, rules, etc.).

  • ACT_RU_*: 'RU' stands for runtime. These are the runtime tables, that contain the runtime data of process instances, user tasks, variables, jobs, etc. Activiti only stores the runtime data during process instance execution, and removes the records when a process instance ends. This keeps the runtime tables small and fast.

  • ACT_ID_*: 'ID'  stands for identity. These tables contain identity information, such as users, groups, etc.

  • ACT_HI_*: 'HI' stands for history. These are the tables that contain historic data, such as past process instances, variables, tasks, etc.

  • ACT_GE_*general data, which is used in various use cases.

升级数据库需要配置databaseSchemaUpdate为true

<beans ... >

  <beanid="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">    <!-- ... -->    <propertyname="databaseSchemaUpdate"value="true"/>        <!-- ... -->  </bean>

</beans>

任务执行器的激活

JobExecutor管理一对线程或者异步消息的组件,以为测试的复杂,被用于多线程。.因此它的api允许(ManagementService.createJobQuery) and执行(ManagementService.executeJob)  ,为了避免执行者的冲突,经常被关闭。默认情况, JobExecutor 被激活当引擎启动时.

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

当你不想在引擎启动的时候激活JobExecutor ,可以设置上面的值为false

邮件服务配置

为了发送邮件,合法的SMTP 服务器是必须的,将下面属性设置到activiti.cfg.xml

Property Required? Description
mailServerHost no 邮件服务器(e.g. mail.mycorp.com). 默认localhost
mailServerPort yes, if not on the default port The port for SMTP traffic on the mail server. The default is 25
mailServerDefaultFrom no The default e-mail address of the sender of e-mails, when none is provided by the user. By default this is activiti@activiti.org
mailServerUsername 如果适用您的服务器 Some mail servers require credentials for sending e-mail. By default not set.
mailServerPassword 如果适用您的服务器 Some mail servers require credentials for sending e-mail. By default not set.
mailServerUseSSL 如果适用您的服务器 Some mail servers require ssl communication. By default set to false.

定义邮件任务

<serviceTask id="sendMail"activiti:type="mail">   

邮件任务通过属性注入方式配置,. 所有的属性值都可以包含 EL 表达式,

Table 8.2. Mail server configuration

Property Required? Description
to yes The recipients if the e-mail. Multiple recipients are defined in a comma-separated list
from no The sender e-mail address. If not provided, the default configured from address is used.
subject no The subject of the e-mail.
cc no The cc's of the e-mail. Multiple recipients are defined in a comma-separated list
bcc no The bcc's of the e-mail. Multiple recipients are defined in a comma-separated list
charset no Allows to change the charset of the email, which is necessary for many non-English languages.
html no A piece of HTML that is the content of the e-mail.
text no The content of the e-mail, in case one needs to send plain none-rich e-mails. Can be used in combination with html, for e-mail clients that don't support rich content. The client will then fall back to this text-only alternative.
邮件任务的例子
<serviceTaskid="sendMail"activiti:type="mail">  <extensionElements>    <activiti:fieldname="from"stringValue="order-shipping@thecompany.com"/>    <activiti:fieldname="to"expression="${recipient}"/>    <activiti:fieldname="subject"expression="Your order ${orderId} has been shipped"/>    <activiti:fieldname="html">      <activiti:expression>        <![CDATA[          <html>            <body>              Hello ${male ? 'Mr.' : 'Mrs.' } ${recipientName},<br/><br/>                               As of ${now}, your order has been <b>processed and shipped</b>.<br/><br/>                                Kind regards,<br/>                                TheCompany.            </body>          </html>        ]]>      </activiti:expression>    </activiti:field>        </extensionElements></serviceTask>                               
历史的配置
<propertyname="history"value="audit"/>
所有的流程定义都会被缓存,下面是设置缓存大小
<propertyname="processDefinitionCacheLimit"value="10"/>使用的是LRU 算法进行缓存策略

日志

在Activiti 5.12, SLF4J日志框架被使用。所有日志(activiti, spring, mybatis, ...)被使用SLF4J ,允许你选择日志框架的实现
默认这个jar包没有在 activiti-engine中引入,需要自己引入。

<dependency>  <groupId>org.slf4j</groupId>  <artifactId>slf4j-log4j12</artifactId> <version>XXX</version></dependency>

t特别重要,当使用容器commons-logging在classpath时: 为了能够路由spring-logging通过SLF4J,  一个桥要被使用

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>jcl-over-slf4j</artifactId>

</dependency>

Activiti-01的更多相关文章

  1. Activiti从当前任务任意回退至已审批任务

    http://www.verydemo.com/demo_c161_i143918.html import java.util.HashMap; import java.util.Iterator; ...

  2. 工作流引擎Activiti 专题

    https://github.com/Activiti/Activiti Quick Start Guide This quick start assumes: Familiarity with Ma ...

  3. Activiti动态设置办理人扩展

    关键词:Assignee.Candidate users.Candidate groups:setAssignee.taskCandidateUser.taskCandidateGroup 主要解决问 ...

  4. 手把手教你如何玩转Activiti工作流

    手把手教你如何玩转Activiti工作流 置顶 2018年01月30日 19:51:36 Cs_hnu_scw 阅读数:24023   版权声明:本文为博主原创文章,未经博主允许不得转载. https ...

  5. 工作流Activiti的学习总结(十二) activiti官方十分钟快速学习 (zhuan)

    http://topmanopensource.iteye.com/blog/1315341 ***************************************************** ...

  6. 【应用篇】Activiti外置表单实例demo(四)

    在这里我想说的外置表单.是说我们将我们自己的jsp(.form,.html)等页面上传到工作流的数据库中,当任务运行到当前结点时.给我们像前台发送绑定好的表单. 此处是给表单绑定表单的过程 water ...

  7. 【Activiti学习之五】BPMN事件

    环境 JDK 1.8 MySQL 5.6 Tomcat 7 Eclipse-Luna activiti 6.0 一.事件定义1.定时器事件(1)timeDate:指定时间触发<timerEven ...

  8. 【Activiti工作流引擎】官方快速入门demo

    Activiti官方快速入门demo 地址: https://www.activiti.org/quick-start 0. 版本 activiti 5.22.0 JDK 1.8 1. 介绍 这个快速 ...

  9. Activiti工作流引擎开发系列

    Activiti工作流引擎开发系列-01 作者:Jesai 没有伞的孩子,只能光脚奔跑! 前言: 初次接触工作流这个概念是自从2014年11月份开始,当时是由于我的毕业设计需要,还记得当时我毕业设计的 ...

  10. 01.SQLServer性能优化之----强大的文件组----分盘存储

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 文章内容皆自己的理解,如有不足之处欢迎指正~谢谢 前天有学弟问逆天:“逆天,有没有一种方 ...

随机推荐

  1. Linux主分区,扩展分区,逻辑分区的联系和区别

    主分区,也称为主磁盘分区,和扩展分区.逻辑分区一样,是一种分区类型.主分区中不能再划分其他类型的分区,因此每个主分区都相当于一个逻辑磁盘(在这一点上主分区和逻辑分区很相似,但主分区是直接在硬盘上划分的 ...

  2. mysql alter使用

    修改表名: ALTER  TABLE Table_name_A RENAME TO Table_name_B; //增加主键 alter table tabelname add new_field_i ...

  3. Windows 8 快捷键

    三月份,Kurt Walter 在 Windows团队博客中发表了一篇介绍 Windows 8 和全新快捷键的精彩文章. Windows 8 提供了出色的触摸体验,但在我的台式机上使用了几个月后我还发 ...

  4. webpack常见的配置总结 ---只是一些常见的配置

    早期的构建工具grunt ,gulp 帮助我们配置一些开发环境,省去一些我们调试和重复的工作 现在我们的构建工具一般是webpack ,目前建议大家用3.0以上的版本 现在市场上比较优秀的构建工具,个 ...

  5. Begin the new life as a coder

    今天刚刚开通博客园的博客频道,这里将成为自我成长点滴记录的土壤!从今天开始,从这篇博文开始,我将分享自己从一个fresher开始的成长经历.原与广大仁人志士共同在程序中共享快乐!我真是太高兴了 :D

  6. C语言格式化输入输出

    %i和%d之间的区别 作为匹配整数的转换说明,printf格式串中两者并没有区别,但是在scanf格式串中%d只能匹配十位制整数,而%i可以匹配八进制(前缀为0,如086).十进制或十六进制(前缀0x ...

  7. SourceTree使用方法介绍

    SourceTree比命令行更容易操作,能更直观看到发生了什么.但是没有哪一家git图形化软件能完成git的所有操作,封装后的使用也隐藏了git的一些细节,在图形化工具出现一些非常罕见的情况时,还是需 ...

  8. Jquery 父级元素、同级元素、子元素

    prev():获取指定元素的上一个同级元素(是上一个哦). prevAll():获取指定元素的前边所有的同级元素. find():查找子元素方式 next(): 获取指定元素的下一个同级元素(注意是下 ...

  9. MySQL (三)-- 字段属性、索引、关系、范式、逆规范化

    1 字段属性 主键.唯一键和自增长. 1.1 主键 主键:primary key,一张表中只能有一个字段可以使用对应的键,用来唯一的约束该字段里面的数据,不能重复. 一张表只能有最多一个主键. 1.1 ...

  10. 使用 LVS 实现负载均衡原理及安装配置详解

    负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F5.Netscale.这里主要是学 ...