软件环境要求
-
JDK1.6或者更高版本l
-
支持的数据库有:h2, mysql, oracle, postgres, mssql, db2等。
-
支持activiti5运行的jar包
-
开发环境为Eclipse3.7或者以上版本
Activiti5 所需jar
-
需要mysql驱动jar包
-
activity5jar包:activiti-5.13\wars\activiti-rest\WEB-INF\lib 中获取
初始化数据库
第一种方式执行sql脚本:
activiti.mysql.create.history.sql
activiti.mysql.create.identity.sql
activiti.mysql.create.engine.sql
第二种方式执行Java代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //1.创建Activiti配置对象的实例 ProcessEngineConfigurationconfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); //2.设置数据库连接信息 // 设置数据库地址 configuration.setJdbcUrl( "jdbc:mysql://localhost:3306/testactiviti?createDatabaseIfNotExist&useUnicode=true&characterEncoding=utf8" ); // 数据库驱动 configuration.setJdbcDriver( "com.mysql.jdbc.Driver" ); // 用户名 configuration.setJdbcUsername( "root" ); // 密码 configuration.setJdbcPassword( "" ); // 设置数据库建表策略 /** * DB_SCHEMA_UPDATE_TRUE:如果不存在表就创建表,存在就直接使用 * DB_SCHEMA_UPDATE_FALSE:如果不存在表就抛出异常 * DB_SCHEMA_UPDATE_CREATE_DROP:每次都先删除表,再创建新的表 */ configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //3.使用配置对象创建流程引擎实例(检查数据库连接等环境信息是否正确) ProcessEngineprocessEngine = configuration.buildProcessEngine(); System.out.println(processEngine); } |
第三种方式使用配置文件方式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < 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/test?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8" ></ property > < property name = "jdbcDriver" value = "com.mysql.jdbc.Driver" ></ property > < property name = "jdbcUsername" value = "root" ></ property > < property name = "jdbcPassword" value = "" ></ property > <!-- 建表策略 --> < property name = "databaseSchemaUpdate" value = "true" ></ property > </ bean > </ beans > |
执行代码:
1 2 3 4 5 6 7 8 9 10 11 | package com.test; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; public class CreateTest { public static void main(String[] args) { // 1。 加载classpath下名为activiti.cfg.xml文件,创建核心流程引擎对象 ProcessEngine processEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource( "activiti.cfg.xml" ).buildProcessEngine(); System.out.println(processEngine); } } |