1. 程式人生 > >建立工作流的23張表

建立工作流的23張表

原始碼下載

方式一:通過程式碼初始化工作流的23張表

/**
  * 通過程式碼初始化工作流的23張表
  */
@Test
public void createActivitiTable(){
   ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
           .createStandaloneProcessEngineConfiguration();
   // 連線數控的配置
   processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver"
); processEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/acti?useUnicode=true&characterEncoding=utf8"); processEngineConfiguration.setJdbcUsername("root"); processEngineConfiguration.setJdbcPassword("jing2018"); /** * DB_SCHEMA_UPDATE_FALSE = "false";不能自動建立表,需要表存在 * DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";先刪除表再建立表 * DB_SCHEMA_UPDATE_TRUE = "true";如果表不存在,自動建立表 */
processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); // ProcessEngine(流程引擎),工作流的核心物件 ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine(); System.out.println("processEngine:" + processEngine); }

方式二:通過配置檔案初始化

/**
  * 使用配置檔案建立工作流資料表
  */
@Test public void createTableByConfig(){ ProcessEngine processEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine(); System.out.println("processEngine:"+processEngine); }

配置檔案

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="processEngineConfiguration"
        class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <!-- 連線資料的配置 -->
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl"
            value="jdbc:mysql://localhost:3306/acti?useUnicode=true&amp;characterEncoding=utf8"/>
        <property name="jdbcUsername" value="root"/>
        <property name="jdbcPassword" value="jing2018"/>
        <!-- 沒有表建立表 -->
        <property name="databaseSchemaUpdate" value="true"/> <!-- true、false、create-drop  -->
    </bean>
</beans>