第一种。

package activitiDemo;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;

public class demo {
    @Test
    public void test(){
        ProcessEngineConfiguration processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
//      数据库的一些配置
        processEngine.setJdbcDriver("com.mysql.jdbc.Driver");
        processEngine.setJdbcUrl("jdbc:mysql://localhost:3306/workflow");
        processEngine.setJdbcUsername("root");
        processEngine.setJdbcPassword("root");
//      表示没有表自动给你创建表
        processEngine.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//      创建工作流引擎
        ProcessEngine buildProcessEngine = processEngine.buildProcessEngine();
        System.out.println(buildProcessEngine);
    }
}

第二种

@Test
    public void test2(){
        ProcessEngineConfiguration processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        ProcessEngine buildProcessEngine = processEngine.buildProcessEngine();
        System.out.println(buildProcessEngine);
    }

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/workflow?useUnicode=true&amp;characterEncoding=utf8"></property>
        <property name="jdbcUsername" value="root"></property>
        <property name="jdbcPassword" value="root"></property>
        <!-- 没有表创建表 -->
        <property name="databaseSchemaUpdate" value="true"></property>
    </bean>

</beans>

log4j.propertites

log4j.rootLogger=INFO, CA

# ConsoleAppender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n

第三种

在前面看到了两种创建ProcessEngine(流程引擎)的方式,而这里要简化很多,调用ProcessEngines的getDefaultProceeEngine方法时会自动加载classpath下名为activiti.cfg.xml文件。

@Test
    public void test3(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(processEngine);
    }

结果就是在数据库中自动给你创建23张表
工作流创建的三种方式_工作流