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. scala 中List的简单使用

    /** * scala 中List的使用 * */ object ListUse { def main(args: Array[String]): Unit = { def decorator(l:L ...

  2. (转载)js引擎的执行过程(一)

    概述 js是一种非常灵活的语言,理解js引擎的执行过程对我们学习javascript非常重要,但是网上讲解js引擎的文章也大多是浅尝辄止或者只局部分析,例如只分析事件循环(Event Loop)或者变 ...

  3. 暴力剪枝——cf1181C

    暴力求长度为len时,以i,j为左上角的旗子的数量 不剪枝的话复杂度是n*n*m*n,必定超时 两个可以剪枝的地方:如果格子[i,j]可以作为长度为len的旗子的左上角,那么其必定不可以作为长度> ...

  4. vue-router 基本操作

    安装 vue-router 在命令行中进入 vue 的项目目录里,运行命令 npm install vue-router --save 来进行安装   npm install vue-router - ...

  5. PowerDesigner导出所有表到Excel(同一表格)

    '****************************************************************************** '* File: pdm2excel.v ...

  6. java读取字符串,生成txt文件

    /** * 读取字符串,生成txt 文件 已解决未设置编码时,在项目中直接打开文件,中文乱码问题 * WriteText.writeToText(musicInfo,fileName)直接调用 * * ...

  7. Geoserver的跨域问题

    使用tomcat访问Geoserver服务的时候,只调服务没问题,但是查询要素属性的时候出现如下“XMLHttpRequest”.“not allowed by Access-Control-Allo ...

  8. Activit单元i测试(与spring集成测试)

    1.测试 eclipse下安装activiti插件以及maven 右键新建activiti project(这时会自动创建pom依赖以及activiti.cfg.xml,但还不是maven项目) 选中 ...

  9. iOS逆向系列-逆向APP思路

    界面分析 通过Cycript.Reveal. 对于Reveal安装配置可参考配置iOS逆向系列-Reveal 通过Reveal找到内存中的UI对象 静态分析 开发者编写的所有代码最终编译链接到Mach ...

  10. apache反向代理和监听多个端口设置

    修改apache配置文件httpd.conf 一.监听多个端口 在Listen 80后添加监听端口,如 Listen 80 Listen 8080 Listen 8008 二.反向代理设置 1.取消一 ...