在开源工作流流程引擎Activiti的过程中,有很多参数是可配置的,例如数据库配置、事务配置、流程引擎内置服务配置等,Activiti通过流程引擎配置对象封装这些配置。本文对Activiti流程引擎的配置进行比较详细的介绍,让读者对各个配置项有深入的理解。
1.流程引擎配置对象
流程引擎配置对象ProcessEngineConfiguration里面有Activiti流程引擎里面的全部配置,为这些可配置的引擎属性提供对是对应的setter合getter方法。该类还提供了很多创建流程引擎配置对象ProcessEngineConfiguration实例的静态方法,这些方法会读取解析配置属性,然后返回对象的实例。该类是一个抽象类,实现类的类图结构如下图。
ProcessEngineConfiguration代表流程引擎的一个配置实例,由于ProcessEngineConfiguration是一个抽象类,我们就要用它的子类去创建bean。官方文档给出了每个实现类的作用。
The activiti.cfg.xml must contain a bean that has the id
processEngineConfiguration
.
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
This bean is then used to construct the
ProcessEngine
. There are multiple classes available that can be used to define the processEngineConfiguration. These classes represent different environments, and set defaults ccordingly. It’s a best practice to select the class the matches (the most) your environment, to minimalise the number of properties needed to configure the engine. The following classes are currently available (more will follow in future releases):
- 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.
- org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: To be used when the engine runs in standalone mode, with JTA transactions.
简单翻译如下:
配置文件activiti.cfg.xml必须有一个id为