Activiti中的流程配置文件

Activiti中的流程配置文件类型可以分为以下两种:

1)普通配置,即Activiti的配置风格,通常情况下,使用该方式的文件名称为activiti.cfg.xml。

2)Spring配置,即Spring配置风格,使用该方式的文件名称可以自定义,例如activiti-context.xml、spring-activiti.xml等。

 

Activiti配置风格

activiti.cfg.xml配置文件的内容如下:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         
    xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
		http://www.springframework.org/schema/context 
	    http://www.springframework.org/schema/context/spring-context-3.1.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
    <!-- 定义一个id为processEngineConfiguration的流程引擎配置类,然后为它设置属性值 -->
    <bean id="processEngineConfiguration" 
            class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <!-- 数据库连接配置 -->
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti_test?
            createDatabaseIfNotExist=true"></property>
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUsername" value="root"></property>
        <property name="jdbcPassword" value="root"></property>
        <!-- 建表策略 -->
        <property name="databaseSchemaUpdate" value="true"></property>
        <!-- 其它省略 -->
    </bean>
</beans>

 

Spring配置风格

 

spring方式创建流程引擎与Activiti单独创建流程引擎是不一样的,区别在于:使用的引擎配置类不一样。

Activiti单独创建:org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration

spring方式创建:org.activiti.spring.SpringProcessEngineConfiguration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    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.xsd">
    <!-- 使用DBCP配置数据源 -->
    <bean id="dataSource_act" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/activiti_test" />
        <property name="username" value="root" />
        <property name="password" value="root" />
    </bean>
    <!-- 事务管理 -->
    <bean id="trManager_act" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource_act" />
    </bean>
    <!-- 自定义流程流程表ID生成策略 -->
    <bean id="uuidGenerator" class="com.zwj.activiti.UUIDGenerator"></bean>
    <!-- 定义流程引擎配置类 -->
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource_act" />
        <property name="transactionManager" ref="trManager_act" />
        <!-- 
            制定要使用的数据库类型
            支持这些值:h2, mysql, oracle, postgres, mssql, db2
        -->
        <property name="databaseType" value="mysql"></property>
        <!-- activiti表中使用uuid主键 -->
    	<property name="idGenerator" ref="uuidGenerator" />
        <!-- 
            设置流程引擎启动和关闭时数据库执行的策略,官方文档提供了以下三个值:
            false:Activiti在启动时,会对比数据库中保存的版本,如果没有表或者版本不匹配,将在启动时抛出异常。
            true:Activiti在启动时,会对数据库中所有表进行更新,如果表不存在,则Activiti会自动创建。
            create-drop:Activiti在启动时会执行表的创建工作,在关闭时会执行表的删除工作。
         -->
        <property name="databaseSchemaUpdate" value="true" />
        <!-- 对数据库中所有表进行更新操作,如果表不存在,则自动创建 -->
    	<property name="databaseSchema" value="ACT"/>
       <!-- 启动或关闭jobexecutor -->
    	<property name="jobExecutorActivate" value="false" />
    	<!-- 不创建identity表,使用视图 -->
    	<property name="dbIdentityUsed" value="false" />
    	<!-- 
            保存流程相关的历史数据
            none:不保存任何历史数据,因此在流程执行中,这是最高效的。
            activity:级别高于none,保存流程实例与流程行为,其他数据不保存。 
            audit:在前者的基础上,还会保存全部的流程任务极其属性。 
            full:保存历史数据的最高级别,除了会保存audit级别的数据外,还会保存其他全部流程相关的细节数据,包括一些流程参数等。
         -->
    	<property name="history" value="full"/>
    	<!-- 邮件服务相关配置 -->
    	<property name="mailServerHost" value="smtp.163.com" />
        <property name="mailServerPort" value="25" />
        <property name="mailServerUsername" value="123456"></property>
        <property name="mailServerPassword" value="xxx"></property>
        <property name="mailServerDefaultFrom" value="[email protected]"></property>
        <!-- 生成流程图的字体 -->
        <property name="activityFontName" value="宋体"/>
        <property name="labelFontName" value="宋体"/>
        <!-- 其它省略 -->
    </bean>
    <!-- 定义流程引擎接口 -->
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    <!-- 定义Service服务接口 -->
    <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" />
    <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />

    <!--自定发布资源文件处理,这里进行处理只有改动的流程引擎才会进行再次发布。 -->
    <!-- <bean id="activitiDeployer" class="wsylp.plugins.WorkflowDeployer"> <property name="deploymentResources" value="classpath*:diagrams/autoDeploy" 
        /> </bean> -->
</beans>

 

history 配置

在流程执行的过程中,会产生一些流程相应的数据,例如流程实例、流程任务和流程参数等数据,随着流程的进行与结束,这些数据将会从流程数据表中删除,为了能保存这些数据,Activiti 提供了历史数据表,可以让这些数据保存到历史数据表中。

对于这些历史数据,保存到何种粒度,Activiti 提供了 history 属性对其进行配置。history属性有点像 log4j 的日志输出级别,该属性有以下四个值:

none:不保存任何的历史数据,因此,在流程执行过程中,这是最高效的。

activity:级别高于 none,保存流程实例与流程行为,其他数据不保存。

audit:除 activity 级别会保存的数据外,还会保存全部的流程任务及其属性。audit为 history 的默认值。

full:保存历史数据的最高级别,除了会保存 audit 级别的数据外,还会保存其他全部流程相关的细节数据,包括一些流程参数等。

 

邮件服务器配置

Activiti 支持邮件服务,当流程执行到某一个节点时,Activiti 会根据流程文件配置(EmailTask),发送邮件到相应的邮箱。以下为 ProcessEngineConfiguration 中提供的邮件服务器配置项:

mailServerHost:邮件服务器地址,非必填,默认值为 localhost。

mailServerPort:SMTP 发送邮邮件服务器端口,默认值为 25。

mailServerDefaultFrom:非必填,发送人的邮箱地址,默认值为 [email protected]

mailServerUsername:邮箱登录用户名。

mailServerPassword:邮箱登录密码。

mailServerUseSSL:是否使用 SSL 协议通信,默认为 false。

mailServerUseTLS:是否使用 TLS 协议通信,默认为 false。

使用 SMTP 协议发送邮件,需要知道邮件服务器地址、SMTP 端口、邮箱登录用户名和密码。以下例子中以网易邮箱为例子,列出如何设置这几个邮件配置项。

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/act" />
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUsername" value="root" />
    <property name="jdbcPassword" value="123456" />
    <property name="mailServerHost" value="smtp.163.com"></property>
    <property name="mailServerPort" value="25"></property>
    <property name="mailServerDefaultFrom" value="[email protected]"></property>
    <property name="mailServerUsername" value="[email protected]"></property>
    <property name="mailServerPassword" value="123456"></property>
</bean> 

 

jobExecutorActivate配置

Activiti中提供了一个工作执行器,执行器会定时到数据库中扫描没有执行的工作,然后使用JobExecutor执行这些工作。JobExecutor会启动一条线程,定时到数据库中查询需要执行的工作,当查询到符合条件的工作时,就会调用executeJobs方法去执行这些工作。

需要注意的是,JobExecutor类是一个抽象类,执行工作的方法交由子类去实现,默认情况下,Activiti使用DefaultJobExecutor类作为JobExecutor。在DefaultJobExecutor中维护了一个ThreadPoolExecutor线程池对象,当工作扫描线程扫描到工作时,就会以这些工作的数据键创建一条线程并交由ThreadPoolExecutor执行。

属性jobExecutorActivate为true,则表示Activiti在流程引擎创建时,需要启动JobExecutor;为false表示不启动JobExecutor,该属性默认值为false。

asyncExecutorActivate配置

Async executor通过线程池的方式管理线程。activiti默认激活使用job executor,要使用async executor替代job executor需在配置文件中定义一下两个属性:

属性asyncExecutorEnabled定义为true,使用async executor代替默认的job executor。

属性asyncExecutorActivate定义为true,工作流引擎在启动时就建立启动async executor线程池。

<property name="asyncExecutorEnabled" value="true" />
<property name="asyncExecutorActivate" value="true" />


相关文章

Activiti流程引擎架构概述

Activiti数据源配置

获取Activiti流程引擎配置信息

 

 

猜你喜欢

转载自blog.csdn.net/lxxiang1/article/details/82432493