第一种方式
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
/**
*activiti工具类
*/
public class InitTable {
public static void createTable(){
//创建数据源
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/spring-activiti");
dataSource.setUsername("root");
dataSource.setPassword("admin");
//创建流程引擎
ProcessEngineConfiguration configuration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
//设置configuration
configuration.setDataSource(dataSource);
/**
* DB_SCHEMA_UPDATE_FALSE = 如果数据库里面没有activiti的表 也不会创建
* DB_SCHEMA_UPDATE_CREATE_DROP = 创建表,使用完后删除
* DB_SCHEMA_UPDATE_TRUE = 如果数据库里没有表,就创建
*
* dorp-create 如果有表,先删除再创建
*/
//配置表的初始化方式
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//得到流程引擎
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
}
public static void main(String[] args) {
createTable();
}
}
第二种方式
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
/**
*
*/
public class InitTable {
public static void createTable(){
//创建流程引擎
ProcessEngineConfiguration configuration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
//设置configuration
configuration.setJdbcDriver("com.mysql.jdbc.Driver");
configuration.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/spring-activiti");
configuration.setJdbcUsername("root");
configuration.setJdbcPassword("admin");
/**
* DB_SCHEMA_UPDATE_FALSE = 如果数据库里面没有activiti的表 也不会创建
* DB_SCHEMA_UPDATE_CREATE_DROP = 创建表,使用完后删除
* DB_SCHEMA_UPDATE_TRUE = 如果数据库里没有表,就创建
*
* dorp-create 如果有表,先删除再创建
*/
//配置表的初始化方式
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//得到流程引擎
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
}
public static void main(String[] args) {
createTable();
}
}
第三种
在src/resources目录下创建activiti.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring-activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="admin" />
<property name="databaseSchemaUpdate" value="drop-create" />
</bean>
</beans>
使用java主方法生成activiti默认的25张表
public void testCreateTableWithXml(){
// 引擎配置
ProcessEngineConfiguration pec=ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// 获取流程引擎对象
ProcessEngine processEngine=pec.buildProcessEngine();
}