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. vba取局域网电脑共享文件夹下的Excel文件

    Private Sub CommandButton1_Click()    Dim xlapp1 As Excel.Application    Dim xlbook1 As Excel.Workbo ...

  2. java8--Stream的flatmap与map异同的理解

    大纲: 异同点 示例 一.异同点 他们的相同点是接收的入参都是一个function. 不同点这个入参function的返回不同.map返回一个对象,flatmap返回一个stream. 这就使得map ...

  3. [JZOJ3362] 【NOI2013模拟】数数

    题目 题目大意 求区间\([A,B]\)有多少个数是"完美的". 一个数是"完美的",当且仅当这个数的各位能分成两个集合,使得两个集合中数字的和相等. \(B\ ...

  4. [JZOJ3303] 【集训队互测2013】城市规划

    题目 题目大意 求\(N\)个点的简单无向图的方案数(有编号). 结果对\(1004535809\)取模. 思考历程 感觉这个问题非常经典. 当时想到了一堆式子,但都觉得可能会有重和漏,于是弃掉了-- ...

  5. Windows start

    启动一个单独的窗口以运行指定的程序或命令. START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]   ...

  6. thinkphp 多层mvc

    hinkPHP基于MVC(Model-View-Controller,模型-视图-控制器)模式,并且均支持多层(multi-Layer)设计. 模型(Model)层 默认的模型层由Model类构成,但 ...

  7. 单层感知机_线性神经网络_BP神经网络

    单层感知机 单层感知机基础总结很详细的博客 关于单层感知机的视频 最终y=t,说明经过训练预测值和真实值一致.下面图是sign函数 根据感知机规则实现的上述题目的代码 import numpy as ...

  8. python模块(转自Yuan先生)

    模块&包(****)                                                                模块(modue)的概念: 在计算机程序的开 ...

  9. 访问配置信息的URL与配置文件的映射关系

  10. 20.multi_case03

    # 多线程 import threading import time class myThread(threading.Thread): def __init__(self, threadID, na ...