Chapter 3. Configuration(配置)
Table of Contents
- Creating a ProcessEngine(建立一個流程引擎)
- ProcessEngineConfiguration bean
- Database configuration(數(shù)據(jù)庫配置)
- Job executor activation(作業(yè)執(zhí)行器激活)
- Mail server configuration(郵件服務(wù)器配置)
- History configuration(歷史配置)
- Supported databases(支持的數(shù)據(jù)庫)
- Changing the database(改變數(shù)據(jù)庫)
- 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文件來配置。注意你采用構(gòu)建流程引擎的Spring風(fēng)格的方式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
文件,并在那個文件的配置之上構(gòu)建一個引擎。下列片段顯示了一個示例配置。下面部分將給出詳細(xì)的配置特性的總體概觀。
<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.
注意配置文件事實(shí)上是一個Spring配置。這并不意味著Activiti只能在Spring環(huán)境下使用! 為了構(gòu)建引擎,我們在內(nèi)部簡單地平衡了解析和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 the buildProcessEngine()
operation, aProcessEngine
is created:
如果需要所有 ProcessEngineConfiguration.createXXX()
的方法返回一個能進(jìn)一步配置的ProcessEngineConfiguration
。在調(diào)用操作之后,建立一個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然后用來構(gòu)建e ProcessEngine
。可以定義processEngineConfiguration
的類有多個。這些類表示不同的環(huán)境,響應(yīng)地設(shè)置為缺省。為了減少需要配置引擎的屬性數(shù)量,選擇的類以匹配環(huán)境是最佳實(shí)踐。當(dāng)前可獲得的類如下(將來的版本將推出新的類)
-
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:以獨(dú)立方式運(yùn)行的流程引擎。Activiti將考慮事務(wù)。缺省地,只有在引擎引導(dǎo)時檢查數(shù)據(jù)庫(如果沒有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將考慮事務(wù)。缺省使用H2內(nèi)存數(shù)據(jù)庫。當(dāng)引擎引導(dǎo)并關(guān)閉時,數(shù)據(jù)庫將被建立和刪除。當(dāng)使用時,可能需要額外的配置(當(dāng)使用作業(yè)執(zhí)行器或者郵件能力的示例除外)
-
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: 當(dāng)在Spring環(huán)境下使用流程引擎時使用。詳情參見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])當(dāng)引擎以帶有JTA事務(wù)的單獨(dú)模式運(yùn)行時使用。
Database configuration(數(shù)據(jù)庫配置)
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:
有兩種方式類配置引擎將使用的數(shù)據(jù)庫。第一個選項(xiàng)是定義數(shù)據(jù)庫的jdbc屬性:
-
jdbcUrl: jdbc url of the database.
jdbcUrl: 數(shù)據(jù)庫的jdbc url。
-
jdbcDriver: implementation of the driver for the specific database type.
jdbcDriver: 特定數(shù)據(jù)庫驅(qū)動的實(shí)現(xiàn)。
-
jdbcUsername: username to connect to the database.
jdbcUsername: 連接到數(shù)據(jù)的用戶名。
-
jdbcPassword: password to connect to the database.
jdbcPassword: 連接到數(shù)據(jù)庫的密碼。
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屬性所構(gòu)建的數(shù)據(jù)源將有的連接池設(shè)置。
-
jdbcMaxActiveConnections: The number of active connections that the connection pool at maximum at any time can contain. Default is 10.
jdbcMaxActiveConnections: 在任何時刻連接池最大能夠包含的可以激活的連接數(shù)。缺省為10.
-
jdbcMaxIdleConnections: The number of idle connections that the connection pool at maximum at any time can contain.
jdbcMaxIdleConnections:在任何時刻連接池最大能夠包含的空閑的連接數(shù)
-
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: 在連接強(qiáng)制返回之前,能夠從連接池檢出一個連接所需的以毫秒計算的時間值。
-
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: 這是一個底層的設(shè)置,給連接池一個打印日志狀態(tài)并重試連接獲取的機(jī)會。在這種情況下通常占用很長時間(以避免如果連接池位置不好導(dǎo)致導(dǎo)致悄無聲息地失敗),缺省時20000(20秒)。
Example database configuration:
示例數(shù)據(jù)庫配置:
<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
的實(shí)現(xiàn)(例如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并不包含允許定義如此數(shù)據(jù)源的Java庫。所以,確保這些(例如,從DBCP而來)在你的classpath里面。
Following properties can be set, regardless of using the jdbc or datasource approach:
不管采用jdbc還是數(shù)據(jù)源方法,可以設(shè)置下列屬性:
-
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: 指示數(shù)據(jù)庫類型。當(dāng)不是采用缺省的H2數(shù)據(jù)庫時xuyao 需要。這個設(shè)置將決定將要使用哪個建立/刪除腳本。要了解支持哪些類型的概要,請參見the 'supported databases' section 。
-
databaseSchemaUpdate: allows to set the strategy to handle the database schema on process engine boot and shutdown.
databaseSchemaUpdate:允許當(dāng)流程引擎引導(dǎo)和關(guān)閉時,設(shè)置處理數(shù)據(jù)庫結(jié)構(gòu)采取的策略。
-
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
(缺省):當(dāng)流程引擎建立時,檢查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
:一旦流程引擎構(gòu)建完成,執(zhí)行一個檢查。如果有必要,更新數(shù)據(jù)庫的結(jié)構(gòu)。如果結(jié)構(gòu)不存在,就創(chuàng)建它。
-
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
:在流程引擎創(chuàng)建時創(chuàng)建結(jié)構(gòu);當(dāng)流程引擎時到達(dá)刪除結(jié)構(gòu)。
Job executor activation(作業(yè)執(zhí)行器激活)
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.
作業(yè)執(zhí)行器是一個管理點(diǎn)火定時器一對線程的組件(之后也叫異步消息)。對于單元測試場景,和多個線程一道工作是麻煩的。所以API允許通過API查詢 (ManagementService.createJobQuery
) 并執(zhí)行作業(yè) (ManagementService.executeJob
) 以便從一個單元測試?yán)锟刂谱鳂I(yè)執(zhí)行。為了避免作業(yè)干擾,可以關(guān)掉它。
By default, the JobExecutor is activated when the process engine boots. Specify
缺省地,當(dāng)流程引擎引導(dǎo)時激活JobExecutor。指定
<property name="jobExecutorActivate" value="false" />
when you don't want the JobExecutor to be activated upon process engine boot.
當(dāng)流程引擎引導(dǎo)時,并不想激活 JobExecutor。
Mail server configuration(郵件服務(wù)器配置)
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 支持在業(yè)務(wù)流程里發(fā)送電子郵件。事實(shí)上,為了發(fā)送郵件,需要配置一個有效的SMTP郵件服務(wù)器配置。這個配置可選項(xiàng)參見e-mail task 。
History configuration(歷史配置)
Optional. Allows to tweak settings that influence the history capabilities of the engine. See history configuration for more details.
可選項(xiàng)。允許影響引擎的歷史能力history capabilities的設(shè)置。詳情參見history configuration 。
<property name="history" value="audit" />
Supported databases(支持的數(shù)據(jù)庫)
Following are the types (case sensitive!) that Activiti uses to refer to databases.
下表是Activiti所使用的數(shù)據(jù)庫表類型(大小寫敏感的)。
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(改變數(shù)據(jù)庫)
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:
在某些點(diǎn)你可能想做的其中一件事是配置來使用不同的數(shù)據(jù)庫。為了配置演示安裝或者為不同數(shù)據(jù)庫產(chǎn)生一個配置文件,遵從這些步驟:
-
Edit setup/build.properties
and change the db
parameter to your type of database {oracle | mysql | postgresql | h2
}.
編輯 setup/build.properties
并將db
參數(shù)變?yōu)槟愕臄?shù)據(jù)庫的類型 {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連接參數(shù)變?yōu)槟闼惭b數(shù)據(jù)庫的那些參數(shù)。
To create a configuration file for your database based on the properties you've specified in the build.*.properties files run
為了建立一個基于你所指定build.*.properties 文件的屬性的配置文件。請運(yùn)行
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
文件夾。產(chǎn)生的配置文件在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
如果你想在另一個數(shù)據(jù)庫上運(yùn)行演示安裝,首先用下面的命令停止示例安裝
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
.
當(dāng)你想使用oracle作為數(shù)據(jù)源來運(yùn)行演示安裝,在調(diào)用ant目標(biāo) demo.start
之前,必須要有額外的步驟: