1.工作流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="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="123456"></property>
<!-- 没有表创建表 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean> </beans>

2.生成工作流23张表(两种方式)

package Junit;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test; public class TestActiviti { /**
* 1.使用代码创建工作流需要的23张表
* 2.流程引擎ProcessEngine对象(所有操作都离不开引擎对象)
*/ @Test
public void createTable () {
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
//连接数据库的配置
processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
processEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8");
processEngineConfiguration.setJdbcUsername("root");
processEngineConfiguration.setJdbcPassword("123456");
//public static final java.lang.String DB_SCHEMA_UPDATE_FALSE = "false";不能自动创建表,需要表存在
//public static final java.lang.String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";先删除表在创建表
//public static final java.lang.String DB_SCHEMA_UPDATE_TRUE = "true";如果表不存在,自动创建表
processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//工作流的核心对象,processEngine对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine(); System.out.println("processEngine: " + processEngine );
} /**
* 使用配置文件创建工作流需要的23张表
*/ @Test
public void createTable2 () {
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); //工作流的核心对象,processEngine对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine(); ProcessEngine processEngine2 = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine(); System.out.println("processEngine2: " + processEngine2 ); }
}
05-07 15:42