public class TestDB {
public static void main(String[] args) {
//1。 创建Activiti配置对象的实例
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
//2. 设置数据库连接信息
// 设置数据库地址
configuration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti_test?createDatabaseIfNotExist=true");
// 数据库驱动
configuration.setJdbcDriver("com.mysql.jdbc.Driver");
// 用户名
configuration.setJdbcUsername("root");
// 密码
configuration.setJdbcPassword("123456");
// 设置数据库建表策略(默认不会建表)
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//3. 使用配置对象创建流程引擎实例(检查数据库连接等环境信息是否正确)
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
}
 public void testDBByProperties() throws Exception {
// 1。 加载classpath下名为activiti.cfg.xml文件,创建核心流程引擎对象
ProcessEngine processEngine = ProcessEngineConfiguration.
                   createProcessEngineConfigurationFromResource("activiti.cfg.xml").
                   buildProcessEngine();
System.out.println(processEngine);
//或者 private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();此方法默认和上面一样
}
}

activiti.cfg.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!-- 数据库连接配置 -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti_test?createDatabaseIfNotExist=true"></property>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="mikesirius"></property>
<!-- 建表策略 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean> </beans>

Spring集成

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置事务管理器,统一事务 -->
<property name="transactionManager" ref="transManager" />
<!-- 设置建表策略 -->
<property name="databaseSchemaUpdate" value="true" />
</bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<!--
bean id repositoryService
RepositoryServicie repositoryService = processEngine.getRepositoryService();
-->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" /> <!-- 流程相关的Service -->
<bean id="workflowService" class="activitiweb.service.impl.WorkflowServiceImpl">
<property name="repositoryService" ref="repositoryService"></property>
<property name="runtimeService" ref="runtimeService"></property>
<property name="taskService" ref="taskService"></property>
<property name="formService" ref="formService"></property>
<property name="historyService" ref="historyService"></property>
</bean> </beans>

核心API介绍

  1、ProcessEngine

    在Activiti中最核心的类,其他的类都是由他而来。

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    可以通过processEngine 的get产生以下Service

RepositoryService

管理流程定义

RuntimeService

执行管理,包括启动、推进、删除流程实例等操作

TaskService

任务管理

HistoryService

历史管理(执行完的数据的管理)

IdentityService

组织机构管理

FormService

一个可选服务,任务表单管理

ManagerService

  2、RepositoryService

    是Activiti的仓库服务类。所谓的仓库指流程定义文档的两个文件:bpmn文件和流程图片。

  3、RuntimeService

    是activiti的流程执行服务类。可以从这个服务类中获取很多关于流程执行相关的信息。

  4、TaskService

    是activiti的任务服务类。可以从这个类中获取任务的信息。

  5、ProcessDefinition

    流程定义类。可以从这里获得资源文件等。

  6、ProcessInstance

    代表流程定义的执行实例。如范冰冰请了一天的假,她就必须发出一个流程实例的申请。一个流程实例包括了所有的运行节点。我们可以利用这个对象来了解当前流程实例的进度等信息。

    从源代码中可以看出ProcessInstance就是Execution,ProcessInstance继承Execution

  7、Execution

    Activiti用这个对象去描述流程执行的每一个节点。在没有并发的情况下,同ProcessInstance。

Activiti核心配置文件,配置流程引擎创建工具的基本参数和数据库连接池参数。

  定义数据库配置参数:

  jdbcUrl: 数据库的JDBC URL。

  jdbcDriver: 对应不同数据库类型的驱动。

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

  jdbcPassword: 连接数据库的密码。

  基于JDBC参数配置的数据库连接 会使用默认的MyBatis连接池。 下面的参数可以用来配置连接池(来自MyBatis参数):

  jdbcMaxActiveConnections: 连接池中处于被使用状态的连接的最大值。默认为10。

  jdbcMaxIdleConnections: 连接池中处于空闲状态的连接的最大值。

  jdbcMaxCheckoutTime: 连接被取出使用的最长时间,超过时间会被强制回收。 默认为20000(20秒)。

  jdbcMaxWaitTime: 这是一个底层配置,让连接池可以在长时间无法获得连接时, 打印一条日志,并重新尝试获取一个连接。(避免因为错误配置导致沉默的操作失败)。 默认为20000(20秒)。

    

Activiti配置实例以及Spring集成配置的更多相关文章

  1. RabbitMQ与spring集成,配置完整的生产者和消费者

    RabbitMQ与AMQP协议详解可以看看这个 http://www.cnblogs.com/frankyou/p/5283539.html 下面是rabbitMQ和spring集成的配置,我配置了二 ...

  2. ActiveMQ Spring 集成配置

    <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms&l ...

  3. RabbitMQ与Spring集成配置

    1.引入相关jar包 //RabbitMQ compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '1. ...

  4. apache-cxf-2.6.3 spring集成配置

    apache-cxf-2.6.3 <?xml version="1.0" encoding="UTF-8"?><beans xmlns=&qu ...

  5. Java配置分离之Spring远程配置

    访问我的博客 前言 集群应用的配置文件如果写在项目的 resources 目录下面,当遇到需要修改某一个配置值时,需要将集群的所有应用的配置信息进行修改,并且将机密的配置信息比如数据库账号密码如果不进 ...

  6. spring通过配置xml文件集成quartz定时器

    概述 Spring为创建Quartzde Scheduler.Trigger和JobDetail提供了方便的FactoryBean类,以便能够在Spring容器中享受注入的好处. 此外,Spring还 ...

  7. spring 事务配置方式以及事务的传播性、隔离级别

    在前面的文章中总结了spring事务的5中配置方式,但是很多方式都不用而且当时的配置使用的所有参数都是默认的参数,这篇文章就看常用的两种事务配置方式并信息配置事务的传播性.隔离级别.以及超时等问题,废 ...

  8. spring-mvc 3.* 多视图解析配置实例 ContentNegotiatingViewResolver

    一.起因     从spring 3.1.0升级到spring 3.2.0时,配置文件servlet.xml中出错. 错误信息: java.lang.String cannot be cast to  ...

  9. MySQL主从备份配置实例

    转载自:https://www.cnblogs.com/ahaii/p/6307648.html MySQL主从备份配置实例 场景: 1.主服务器192.168.0.225.从服务器192.168.0 ...

随机推荐

  1. 检测到“RuntimeLibrary”的不匹配项

  2. 使用FastJson转化Json格式

    1.下载Jar包 http://repo1.maven.org/maven2/com/alibaba/fastjson/ 2.将jar包导入工程 3.示例 package nc.testFastJso ...

  3. Bugs Integrated, Inc.

    Bugs Integrated, Inc. 给出一个\(n\times m\)的矩形网格图,给出其中K个障碍物的位置,求其中最多能摆的\(2\times 3\)的矩形的个数,\(n\leq 150,m ...

  4. duilib教程之duilib入门简明教程12.简单控件介绍

    前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用.    由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界面比较土鳖 ...

  5. 杂项-IM:IM(即时通讯),一种基于互联网的即时交流消息的业务

    ylbtech-杂项-IM:IM(即时通讯),一种基于互联网的即时交流消息的业务 即时通讯(Instant Messaging)是目前Internet上最为流行的通讯方式,各种各样的即时通讯软件也层出 ...

  6. System.Drawing.Graphics.cs

    ylbtech-System.Drawing.Graphics.cs 1.程序集 System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKey ...

  7. 盒子阴影 box-shadow

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 夏令营501-511NOIP训练18——高三楼

    传送门:QAQQAQ 题意:定义矩阵A与矩阵B重复,当且仅当A可以通过任意次行列交换得到B,例如下图A,B即为合法矩阵 现求对于$n*n$的矩阵有多少个不重复的矩阵 数据范围: 对于10%的数据 N≤ ...

  9. 使用maven搭建Hibernate

    使用maven搭建Hibernate框架(web项目) create table USERS ( ID NUMBER not null primary key, NAME ), PASSWORD ), ...

  10. 5.1_Spring Boot2.x安装Docker

    1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker 是一个开源的应用容器引擎,基于Go 语言并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的应用 ...