activiti配置

 activiti Configuration(配置)

Table of Contents

Creating a ProcessEngine(建立一个流程引擎) ProcessEngineConfiguration bean Database configuration(数据库配置) Job executor activation(作业执行器激活) Mail server configuration(邮件服务器配置) History configuration(历史配置) Supported databases(支持的数据库) Changing the database(改变数据库) Downloading the Oracle driver(下载Oracle)
Creating a ProcessEngine(建立一个流程引擎)

The Activiti process engine is configured through a xml file called activiti.cfg.xml. Note that this is not applicable if you're using the Spring style of building a process engine.

Activiti流程引擎通过一个叫做的xml文件来配置。注意你采用构建流程引擎的Spring风格的方式the Spring style of building a process engine,这种方式并不适合

The easiest way to obtain a ProcessEngine, is to use the org.activiti.engine.ProcessEngines class:

获取ProcessEngine最容易的方式是使用org.activiti.engine.ProcessEngines类:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()

This will look for an activiti.cfg.xml file on the classpath and construct an engine based on the configuration in that file. The following snippet shows an example configuration. The following sections will give a detailed overview of the configuration properties.

这将在classpath上寻找 activiti.cfg.xml文件,并在那个文件的配置之上构建一个引擎。下列片段显示了一个示例配置。下面部分将给出详细的配置特性的总体概观。

<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">
<property name="databaseType" value="h2" />
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</bean>
</beans>

Note that the configuration xml is in fact a Spring configuration. This does not mean that Activiti can only be used in a Spring environment! We are simply leveraging the parsing and dependency injection capabilitities of Spring internally for building up the engine.

注意配置文件事实上是一个Spring配置。这并不意味着Activiti只能在Spring环境下使用! 为了构建引擎,我们在内部简单地平衡了解析和Spring的依赖注入的能力。

The ProcessEngineConfiguration object can also be created programmatically using the configuration file. It is also possible to use a different bean id (eg. see line 3).

通过使用配置文件,也能通过编程方式建立ProcessEngineConfiguration对象。使用一个不同的bean id也是可能的。(例如,见第3行)。

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

It is also possible not to use a configuration file, and create a configuration based on defaults (see the different supported classes for more information).

不使用配置文件也是可能的,基于缺省建立一个配置(详情参见不同支持的类(the different supported classes))

ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();

All these ProcessEngineConfiguration.createXXX() methods return a ProcessEngineConfiguration that can further be tweaked if needed. After calling thebuildProcessEngine() operation, aProcessEngine is created:

如果需要所有 ProcessEngineConfiguration.createXXX()的方法返回一个能进一步配置的ProcessEngineConfiguration 。在调用操作之后,建立一个ProcessEngine 。

ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
.setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
.setJobExecutorActivate(true)
.buildProcessEngine();
ProcessEngineConfiguration bean

The activiti.cfg.xml must contain a bean that has the id 'processEngineConfiguration'.

dd activiti.cfg.xml 必须包括具有id 'processEngineConfiguration'的bean。

 <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 accordingly. 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. Following classes are currently available (more will follow in future releases):

得到这个bean然后用来构建e ProcessEngine。可以定义processEngineConfiguration的类有多个。这些类表示不同的环境,响应地设置为缺省。为了减少需要配置引擎的属性数量,选择的类以匹配环境是最佳实践。当前可获得的类如下(将来的版本将推出新的类)

  • 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.StandaloneProcessEngineConfiguration:以独立方式运行的流程引擎。Activiti将考虑事务。缺省地,只有在引擎引导时检查数据库(如果没有Activiti schema或者schema版本不正确,将抛出异常)。

  • org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration: this is a convience 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.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration: 这是一个针对单元测试目的的便捷类。Activiti将考虑事务。缺省使用H2内存数据库。当引擎引导并关闭时,数据库将被建立和删除。当使用时,可能需要额外的配置(当使用作业执行器或者邮件能力的示例除外)

  • 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.spring.SpringProcessEngineConfiguration: 当在Spring环境下使用流程引擎时使用。详情参见Spring集成部分the Spring integration section

  • org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: ([EXPERIMENTAL]) to be used when the engine runs in standalone mode, with JTA transactions.

    org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: ([EXPERIMENTAL])当引擎以带有JTA事务的单独模式运行时使用。

Database configuration(数据库配置)

There are two ways to configure the database that the Activiti engine will use. The first option is to define the jdbc properties of the database:

有两种方式类配置引擎将使用的数据库。第一个选项是定义数据库的jdbc属性:

  • jdbcUrl: jdbc url of the database.

    jdbcUrl: 数据库的jdbc url。

  • jdbcDriver: implementation of the driver for the specific database type.

    jdbcDriver: 特定数据库驱动的实现。

  • jdbcUsername: username to connect to the database.

    jdbcUsername: 连接到数据的用户名。

  • jdbcPassword: password to connect to the database.

    jdbcPassword: 连接到数据库的密码。

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

基于所提供的jdbc属性所构建的数据源将有的连接池设置。

  • jdbcMaxActiveConnections: The number of active connections that the connection pool at maximum at any time can contain. Default is 10.

    jdbcMaxActiveConnections: 在任何时刻连接池最大能够包含的可以激活的连接数。缺省为10.

  • jdbcMaxIdleConnections: The number of idle connections that the connection pool at maximum at any time can contain.

    jdbcMaxIdleConnections:在任何时刻连接池最大能够包含的空闲的连接数

  • jdbcMaxCheckoutTime: The amount of time in milliseconds a connection can be 'checked out' from the connection pool before it is forcefully returned. Default is 20000 (20 seconds).

    jdbcMaxCheckoutTime: 在连接强制返回之前,能够从连接池检出一个连接所需的以毫秒计算的时间值。

  • jdbcMaxWaitTime: This is a low level setting that gives the pool a chance to print a log status and re-attempt the acquisition of a connection in the case that it’s taking unusually long (to avoid failing silently forever if the pool is misconfigured) Default is 20000 (20 seconds).

    jdbcMaxWaitTime: 这是一个底层的设置,给连接池一个打印日志状态并重试连接获取的机会。在这种情况下通常占用很长时间(以避免如果连接池位置不好导致导致悄无声息地失败),缺省时20000(20秒)。

Example database configuration:

示例数据库配置:

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

Alternatively, a javax.sql.DataSource implementation can be used (eg. DBCP from ):

可选,可以使用 javax.sql.DataSource的实现(例如Apache Commons的DBCP):

<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">
<property name="dataSource" ref="dataSource" />
...

Note that Activiti does not ship with a library that allows to define such datasource. So you have to make sure that the libraries (eg. from DBCP) are on your classpath.

注意Activiti并不包含允许定义如此数据源的Java库。所以,确保这些(例如,从DBCP而来)在你的classpath里面。

Following properties can be set, regardless of using the jdbc or datasource approach:

不管采用jdbc还是数据源方法,可以设置下列属性:

  • databaseType: indicates the type of database. This property is required when not using the default H2 database This setting will determine which create/drop scripts and queries will be used. See the 'supported databases' section for an overview of which types are supported.

    databaseType: 指示数据库类型。当不是采用缺省的H2数据库时xuyao 需要。这个设置将决定将要使用哪个建立/删除脚本。要了解支持哪些类型的概要,请参见the 'supported databases' section 。

  • databaseSchemaUpdate: allows to set the strategy to handle the database schema on process engine boot and shutdown.

    databaseSchemaUpdate:允许当流程引擎引导和关闭时,设置处理数据库结构采取的策略。

    • false (default): Checks the version of the DB schema against the library when the process engine is being created and throws an exception if the versions don't match.

      false (缺省):当流程引擎建立时,检查DB和库的版本。如果版本不匹配,将抛出异常。

    • true: Upon building of the process engine, a check is performed and an update of the schema is performed if it is necessary. If the schema doesn't exist, it is created.

      true:一旦流程引擎构建完成,执行一个检查。如果有必要,更新数据库的结构。如果结构不存在,就创建它。

    • create-drop: Creates the schema when the process engine is being created and drops the schema when the process engine is being closed.

      create-drop:在流程引擎创建时创建结构;当流程引擎时到达删除结构。

Job executor activation(作业执行器激活)

The JobExecutor is a component that manages a couple of threads to fire timers (and later also asynchronous messages). For unit testing scenarios, it is cumbersome to work with multiple threads. Therefor the API allows to query for (ManagementService.createJobQuery) and execute jobs (ManagementService.executeJob) through the API so that job execution can be controlled from within a unit test. To avoid that the job executor interferes, it can be turned off.

作业执行器是一个管理点火定时器一对线程的组件(之后也叫异步消息)。对于单元测试场景,和多个线程一道工作是麻烦的。所以API允许通过API查询 (ManagementService.createJobQuery) 并执行作业 (ManagementService.executeJob) 以便从一个单元测试里控制作业执行。为了避免作业干扰,可以关掉它。

By default, the JobExecutor is activated when the process engine boots. Specify

缺省地,当流程引擎引导时激活JobExecutor。指定

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

when you don't want the JobExecutor to be activated upon process engine boot.

当流程引擎引导时,并不想激活 JobExecutor。

Mail server configuration(邮件服务器配置)

Optional. Activiti supports sending e-mails in business processes. To actually send an e-mail, a valid SMTP mail server configuration is required. See the e-mail task for the configuration options.

可选。. Activiti 支持在业务流程里发送电子邮件。事实上,为了发送邮件,需要配置一个有效的SMTP邮件服务器配置。这个配置可选项参见e-mail task 。

History configuration(历史配置)

Optional. Allows to tweak settings that influence the history capabilities of the engine. See history configuration for more details.

可选项。允许影响引擎的历史能力history capabilities的设置。详情参见history configuration 。

<property name="history" value="audit" />
Supported databases(支持的数据库)

Following are the types (case sensitive!) that Activiti uses to refer to databases.

下表是Activiti所使用的数据库表类型(大小写敏感的)。

Table 1.1. Supported databases

Activiti database type
Versions tested
Notes

h2
1.2.132
Default configured database

mysql
5.1.11

oracle
10.2.0

postgres
8.4

db2
not yet supported (coming soon, see ACT-330)

mssql
not yet supported (coming soon)

Changing the database(改变数据库)

One of the things you probably want to do at some point, is configuring Activiti to use a different database. To configure the demo setup or to generate a configuration file for a different database, follow these steps:

在某些点你可能想做的其中一件事是配置来使用不同的数据库。为了配置演示安装或者为不同数据库产生一个配置文件,遵从这些步骤:

  • Edit setup/build.properties and change the db parameter to your type of database {oracle | mysql | postgresql | h2}.

    编辑 setup/build.properties 并将db参数变为你的数据库的类型 {oracle | mysql | postgresql | h2}。

  • Edit setup/build.${db}.properties and change the JDBC connection parameters to those of your database installation.

    编辑setup/build.${db}.properties并将JDBC连接参数变为你所安装数据库的那些参数。

To create a configuration file for your database based on the properties you've specified in the build.*.properties files run

为了建立一个基于你所指定build.*.properties 文件的属性的配置文件。请运行

ant cfg.create

from within the setup folder. The generate configuration file can now be found in setup/build/activiti-cfg. Also, for convenience, a jar called containing the configuration file can be found in setup/build

setup 文件夹。产生的配置文件在setup/build/activiti-cfg里能够找到。 为了方便起见,一个叫activiti-cfg.jar的jar包包含了能够在setup/build 里找到的配置文件。

If you want to run the demo setup on another database, first stop the demo setup with

如果你想在另一个数据库上运行演示安装,首先用下面的命令停止示例安装

ant demo.stop demo.clean demo.start

Then clean and re-start the demo setup with

然后清除并重新启动演示安装:

ant demo.clean demo.start
Downloading the Oracle driver(下载Oracle)

When you want to run the demo setup using oracle as datasource, an extra step is required BEFORE you call the ant target demo.start.

当你想使用oracle作为数据源来运行演示安装,在调用ant目标 demo.start,必须要有额外的步骤:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值