activiti工作流

2019/09/29 工作流 共 5425 字,约 16 分钟

工作流

工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程自动进行,从而实现某个预期的业务目标,或者促使此目标的实现”。

工作流管理系统(Workflow Management System, WfMS)是一个软件系统,它完成工作量的定义和管理,并按照在系统中预先定义好的工作流规则进行工作流实例的执行。工作流管理系统不是企业的业务系统,而是为企业的业务系统的运行提供了一个软件的支撑环境。

Activiti6.0

Activiti成熟、稳定、满足BPMN2.0规范。在国内用户众多,社区活跃,底层是基于spring、Mybatis等常用互联网技术堆栈,因而我们对于工作流的使用就选择Activiti。

下面先直接进入一个helloworld

helloworld

官网下载activiti6.0 : https://www.activiti.org

在官网中找到快速开始,下载activiti6.0的包 https://www.activiti.org/get-started

将下载的包中的wars文件夹下的activiti-app.war包放入tomcat中启动即可。

这样只是启动了别人的war包,下面我们来通过源码启动activiti6.0的示例工程。

获取源码

通过github fork一份。然后拉下来,这里不会用git的同志得去自己学一下。

1569811632148

然后我们切换到 6.X分支上。切换完后目录如下

1571304820434

activiti-app项目就在modules中

1571304878224

当然刚开始是灰色的,需要在maven中添加上这个项目的pom文件。

1571304958171

然后添加tomcat,放入项目,注意红框内容,后面再解释。

下一步修改配置文件,连接到本地库。

1571305150747

启动项目,OK了。

流程引擎配置ProcessEngineConfiguration

activiti中流程引擎配置对象可以生成流程引擎对象,而通过流程引擎对象又能获取到各个service对象,然后对各个流程进行操作。因而流程的第一步就是获取流程引擎对象。

流程引擎配置对象可以通过静态方法来获取

1571048489194

他们都是通过不同的方式来读取配置文件后生成配置对象。

ProcessEngineConfiguration 是一个抽象类,它直接被ProcessEngineConfigurationImpl继承,下面还有具体的实现类。如下图

1571133283806

我们先看看ProcessEngineConfiguration 中的主要属性

//下面这三个是对数据库表的设置,false-不会对数据库进行修改,没有引擎需要的表就会报错。
// create-drop - 引擎启动时创建表,关闭时会将表销毁
// true - 当没有引擎需要的表时会自己创建。(版本升级后会自己更新)
public static final String DB_SCHEMA_UPDATE_FALSE = "false";
public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";
public static final String DB_SCHEMA_UPDATE_TRUE = "true";

/** The tenant id indicating 'no tenant' */
public static final String NO_TENANT_ID = "";

protected String processEngineName = ProcessEngines.NAME_DEFAULT;
protected int idBlockSize = 2500;
protected String history = HistoryLevel.AUDIT.getKey();
protected boolean asyncExecutorActivate;
	//流程引擎邮件的设置
protected String mailServerHost = "localhost";
protected String mailServerUsername; // by default no name and password are provided, which
protected String mailServerPassword; // means no authentication for mail server
protected int mailServerPort = 25;
protected boolean useSSL;
protected boolean useTLS;
protected String mailServerDefaultFrom = "activiti@localhost";
protected String mailSessionJndi;
protected Map<String, MailServerInfo> mailServers = new HashMap<String, MailServerInfo>();
protected Map<String, String> mailSessionsJndi = new HashMap<String, String>();

//数据库的设置(默认会从jdbcDriver里获取),也可自己设置
protected String databaseType;
//默认的数据库连接设置,是一个内存数据库。
protected String databaseSchemaUpdate = DB_SCHEMA_UPDATE_FALSE;
protected String jdbcDriver = "org.h2.Driver";
protected String jdbcUrl = "jdbc:h2:tcp://localhost/~/activiti";
protected String jdbcUsername = "sa";
protected String jdbcPassword = "";
protected String dataSourceJndiName;
//是否需要身份信息表
protected boolean isDbIdentityUsed = true;
//是否保留历史数据(历史数据表)
protected boolean isDbHistoryUsed = true;
//历史记录级别 none:不记录历史流程,性能高,流程结束后不可读取
//			activiti:归档流程实例和活动实例,但不记录流程变量。没有流程细节
//      默认配置 audit: 在activiti基础上保存变量,和表单属性
//     full:记录所有细节和变化,性能较差。
protected HistoryLevel historyLevel;
protected int jdbcMaxActiveConnections;
protected int jdbcMaxIdleConnections;
protected int jdbcMaxCheckoutTime;
protected int jdbcMaxWaitTime;
protected boolean jdbcPingEnabled;
protected String jdbcPingQuery;
protected int jdbcPingConnectionNotUsedFor;
protected int jdbcDefaultTransactionIsolationLevel;
protected DataSource dataSource;
protected boolean transactionsExternallyManaged;

protected String jpaPersistenceUnitName;
protected Object jpaEntityManagerFactory;
protected boolean jpaHandleTransaction;
protected boolean jpaCloseEntityManager;

protected Clock clock;
protected AsyncExecutor asyncExecutor;
/**
   * Define the default lock time for an async job in seconds. The lock time is used when creating an async job and when it expires the async executor assumes that the job has failed. It will be
   * retried again.
*/
protected int lockTimeAsyncJobWaitTime = 60;
/** define the default wait time for a failed job in seconds */
protected int defaultFailedJobWaitTime = 10;
/** define the default wait time for a failed async job in seconds */
protected int asyncFailedJobWaitTime = 10;

/**
   * process diagram generator. Default value is DefaulProcessDiagramGenerator
	流程图渲染的工具
*/
protected ProcessDiagramGenerator processDiagramGenerator;

	//数据库表前缀的设置 如加上 PRE1 'PRE1.ACT_RU_EXECUTION_'
protected String databaseTablePrefix = "";

/**
   * Escape character for doing wildcard searches.
*
   * This will be added at then end of queries that include for example a LIKE clause.
   * For example: SELECT * FROM table WHERE column LIKE '%\%%' ESCAPE '\';
*/
protected String databaseWildcardEscapeCharacter;

/**
   * database catalog to use
*/
protected String databaseCatalog = "";

/**
   * In some situations you want to set the schema to use for table checks / generation if the database metadata doesn't return that correctly, see https://jira.codehaus.org/browse/ACT-1220,
   * https://jira.codehaus.org/browse/ACT-1062
*/
protected String databaseSchema;

/**
   * Set to true in case the defined databaseTablePrefix is a schema-name, instead of an actual table name prefix. This is relevant for checking if Activiti-tables exist, the databaseTablePrefix will
   * not be used here - since the schema is taken into account already, adding a prefix for the table-check will result in wrong table-names.
*
   * @since 5.15
*/
protected boolean tablePrefixIsSchema;

protected boolean isCreateDiagramOnDeploy = true;

protected String xmlEncoding = "UTF-8";

protected String defaultCamelContext = "camelContext";

protected String activityFontName = "Arial";
protected String labelFontName = "Arial";
protected String annotationFontName = "Arial";

protected ClassLoader classLoader;
/**
   * Either use Class.forName or ClassLoader.loadClass for class loading. See http://forums.activiti.org/content/reflectutilloadclass-and-custom- classloader
*/
protected boolean useClassForNameClassLoading = true;
protected ProcessEngineLifecycleListener processEngineLifecycleListener;

protected boolean enableProcessDefinitionInfoCache = false;
protected ActivitiEngineAgendaFactory engineAgendaFactory;

文档信息

Search

    Table of Contents