Activiti-01
1, Activiti官網:http://www.activiti.org/? 主頁可以看到jar包的下載.
2, 進入http://www.activiti.org/userguide/index.html?用戶指導頁進行學習研究.
3, 在maven中引入activiti jar 文件的
To include the activiti engine in your project, add following dependency (note that you need to change the version to the latest release):
<dependency><groupId>org.activiti</groupId><artifactId>activiti-engine</artifactId><version>5.x</version> </dependency>And if you use Activiti with the Spring integration, then your dependencies could look like this:
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>spring.version</version> </dependency> <dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>spring.version</version> </dependency> <dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>spring.version</version> </dependency>4, 如果不使用maven,可以在下載的zip包的libs文件夾中看到所有的jar文件(包括源文件jar)必須的依賴包
org.activiti:activiti-engine:jar:5.12.1+- org.apache.commons:commons-email:jar:1.2:compile
| ?+- javax.mail:mail:jar:1.4.1:compile
| ?\- javax.activation:activation:jar:1.1:compile
+- commons-lang:commons-lang:jar:2.4:compile
+- org.mybatis:mybatis:jar:3.1.1:compile
+- org.springframework:spring-beans:jar:3.1.2.RELEASE:compile
| ?\- org.springframework:spring-core:jar:3.1.2.RELEASE:compile
| ? ? +- org.springframework:spring-asm:jar:3.1.2.RELEASE:compile
| ? ? \- commons-logging:commons-logging:jar:1.1.1:compile
\- joda-time:joda-time:jar:2.1:compile
?
Note: the mail jars are only needed if you are using the?mail service task
得到ProcessEngine對象是很容易的,會去classpath中找?activiti.cfg.xml文件. ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
<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">
?
? ? <propertyname="jdbcUrl"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
? ? <propertyname="jdbcDriver"value="org.h2.Driver"/>
? ? <propertyname="jdbcUsername"value="sa"/>
? ? <propertyname="jdbcPassword"value=""/>
? ?
? ? <propertyname="databaseSchemaUpdate"value="true"/>
? ?
? ? <propertyname="jobExecutorActivate"value="false"/>
? ?
? ? <propertyname="mailServerHost"value="mail.my-corp.com"/>
? ? <propertyname="mailServerPort"value="5025"/> ? ?
? </bean>
</beans>
5? 這是一個基于Spring的xml文件,但是并不意味著它只能在spring中配置
?????? ProcessEngineConfiguration 對象可以使用配置文件創建也可以指定自己的bean名稱,如
ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource,String beanName);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream,String beanName);
所有ProcessEngineConfiguration.createXXX()?方法返回ProcessEngineConfiguration對象,再調用buildProcessEngine()方法即可返回ProcessEngine?對象。
?
activiti.cfg.xml?必須有一個bean的id為 ?'processEngineConfiguration'.,這個bean是用來構造ProcessEngine的
??? <bean id="processEngineConfiguration"
?? class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> ,class可以指定的類
?
-
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. See?the Spring integration section?for more information.
-
org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration: To be used when the engine runs in standalone mode, with JTA transactions.
有兩種方式配置Activiti引擎用到的數據庫,第一種是jdbc方式
?
<propertyname="jdbcUrl"value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/><propertyname="jdbcDriver"value="org.h2.Driver"/>
<propertyname="jdbcUsername"value="sa"/>
<propertyname="jdbcPassword"value=""/>
The data source that is constructed based on the provided JDBC properties will have the default?MyBatis?connection pool settings. The following attributes can optionally be set to tweak that connection pool (taken from the MyBatis documentation):
基于JDBC屬性構造數據源的方式默認使用Mybatis連接池設置,下面屬性可以設置調整連接池-
jdbcMaxActiveConnections: 最大活動連接數. Default is 10.
-
?jdbcMaxIdleConnections:? 空閑連接數
-
jdbcMaxCheckoutTime: 一個連接在返回之前被檢查的時間 . Default is 20000 (20 seconds).
-
jdbcMaxWaitTime: 這是一個低級設置,一般都是默認不修改 Default is 20000 (20 seconds).
? <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">
?
? ? <propertyname="dataSource"ref="dataSource"/>
...
>
必須確保數據源的依賴庫在classpath中
下面屬性也應該被設置,無論是jdbc還是data source
?databaseType: 數據庫類型? ,可能的取值 {h2, mysql, oracle, postgres, mssql, db2}
?? ?databaseSchemaUpdate:? 流程引擎啟動關閉時數據庫的策略.
??????????????????????????? ? false 默認:檢查數據庫schema版本,在流程引擎創建或拋異常時
true 在部署流程引擎時,檢查數據庫schema,不存在就創建create-drop 在流程引擎創建時創建數據庫schema,關閉時刪除數據庫schema 在 activiti-5.13/database下可以看到可以看到具體的sql dll文件
-
engine:?引擎執行必須的表. Required.
-
identity:? 這些表包含用戶,組,用戶在組中的身份,是可選的 這些表應該被使用當使用默認的身份管理引擎的裝載.
-
history:?包含歷史和審計信息.?可選的,當歷史級別設置為none時是不需要的?
?????
?
Activiti數據庫都以ACT_開頭 .
?
???????? ACT_RE_*: ?'RE' stands for?repository. Tables with this prefix contain 'static' information such as process definitions and process resources (images, rules, etc.).
?
-
ACT_RU_*: 'RU' stands for?runtime. These are the runtime tables, that contain the runtime data of process instances, user tasks, variables, jobs, etc. Activiti only stores the runtime data during process instance execution, and removes the records when a process instance ends. This keeps the runtime tables small and fast.
-
ACT_ID_*: 'ID'? stands for?identity. These tables contain identity information, such as users, groups, etc.
-
ACT_HI_*: 'HI' stands for?history. These are the tables that contain historic data, such as past process instances, variables, tasks, etc.
-
ACT_GE_*:?general?data, which is used in various use cases.
?
升級數據庫需要配置databaseSchemaUpdate為true<beans ... >
? <beanid="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
? ? <!-- ... -->
? ? <propertyname="databaseSchemaUpdate"value="true"/> ? ?
? ? <!-- ... -->
? </bean>
</beans>
?
任務執行器的激活
?JobExecutor管理一對線程或者異步消息的組件,以為測試的復雜,被用于多線程。.因此它的api允許(ManagementService.createJobQuery) and執行(ManagementService.executeJob)? ,為了避免執行者的沖突,經常被關閉。默認情況,?JobExecutor?被激活當引擎啟動時.
?
<property name="jobExecutorActivate"value="false"/>?
當你不想在引擎啟動的時候激活JobExecutor?,可以設置上面的值為false
?
郵件服務配置
為了發送郵件,合法的SMTP?服務器是必須的,將下面屬性設置到activiti.cfg.xml
?
| mailServerHost | no | 郵件服務器(e.g. mail.mycorp.com). 默認localhost |
| mailServerPort | yes, if not on the default port | The port for SMTP traffic on the mail server. The default is?25 |
| mailServerDefaultFrom | no | The default e-mail address of the sender of e-mails, when none is provided by the user. By default this is?activiti@activiti.org |
| mailServerUsername | 如果適用您的服務器 | Some mail servers require credentials for sending e-mail. By default not set. |
| mailServerPassword | 如果適用您的服務器 | Some mail servers require credentials for sending e-mail. By default not set. |
| mailServerUseSSL | 如果適用您的服務器 | Some mail servers require ssl communication. By default set to false. |
定義郵件任務
?
<serviceTask id="sendMail"activiti:type="mail"> ?郵件任務通過屬性注入方式配置,.?所有的屬性值都可以包含 EL 表達式,
Table?8.2.?Mail server configuration
| to | yes | The recipients if the e-mail. Multiple recipients are defined in a comma-separated list |
| from | no | The sender e-mail address. If not provided, the?default configured?from address is used. |
| subject | no | The subject of the e-mail. |
| cc | no | The cc's of the e-mail. Multiple recipients are defined in a comma-separated list |
| bcc | no | The bcc's of the e-mail. Multiple recipients are defined in a comma-separated list |
| charset | no | Allows to change the charset of the email, which is necessary for many non-English languages. |
| html | no | A piece of HTML that is the content of the e-mail. |
| text | no | The content of the e-mail, in case one needs to send plain none-rich e-mails. Can be used in combination with?html, for e-mail clients that don't support rich content. The client will then fall back to this text-only alternative. |
id="sendMail"activiti:type="mail">
? <extensionElements>
? ? <activiti:fieldname="from"stringValue="order-shipping@thecompany.com"/>
? ? <activiti:fieldname="to"expression="${recipient}"/>
? ? <activiti:fieldname="subject"expression="Your order ${orderId} has been shipped"/>
? ? <activiti:fieldname="html">
? ? ? <activiti:expression>
? ? ? ? <![CDATA[
? ? ? ? ? <html>
? ? ? ? ? ? <body>
? ? ? ? ? ? ? Hello ${male ? 'Mr.' : 'Mrs.' } ${recipientName},<br/><br/>
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? As of ${now}, your order has been <b>processed and shipped</b>.<br/><br/>
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? Kind regards,<br/>
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? TheCompany.
? ? ? ? ? ? </body>
? ? ? ? ? </html>
? ? ? ? ]]>
? ? ? </activiti:expression>
? ? </activiti:field> ? ? ?
? </extensionElements>
</serviceTask> ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? 歷史的配置
<propertyname="history"value="audit"/> 所有的流程定義都會被緩存,下面是設置緩存大小 <propertyname="processDefinitionCacheLimit"value="10"/>
使用的是LRU?算法進行緩存策略
日志
在Activiti 5.12, SLF4J日志框架被使用。所有日志(activiti, spring, mybatis, ...)被使用SLF4J ,允許你選擇日志框架的實現
默認這個jar包沒有在?activiti-engine中引入,需要自己引入。
?
<dependency>? <groupId>org.slf4j</groupId>
? <artifactId>slf4j-log4j12</artifactId>
<version>XXX</version>
</dependency>
?
?
t特別重要,當使用容器commons-logging在classpath時:?為了能夠路由spring-logging通過SLF4J,? 一個橋要被使用
<dependency>
?<groupId>org.slf4j</groupId>
?<artifactId>jcl-over-slf4j</artifactId>
</dependency>
轉載于:https://www.cnblogs.com/yangw/p/3373862.html
總結
以上是生活随笔為你收集整理的Activiti-01的全部內容,希望文章能夠幫你解決所遇到的問題。