Activiti学习记录
Posted fanjava
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti学习记录相关的知识,希望对你有一定的参考价值。
1.初始化数据库
使用工作流引擎创建23张表
public class TestActiviti { /** * 使用代码创建工作流需要的23张表 */ @Test public void createTable() { ProcessEngineConfiguration createStandaloneProcessEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); createStandaloneProcessEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver"); createStandaloneProcessEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti0710?useUnicode=true&characterEncoding=utf8"); createStandaloneProcessEngineConfiguration.setJdbcUsername("root"); /** public static final String DB_SCHEMA_UPDATE_FALSE = "false"; 不能自动创建表,需要表存在 public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop"; 表示先删除表,在创建表 public static final String DB_SCHEMA_UPDATE_TRUE = "true";如果表不存在,自动创建表 */ createStandaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(createStandaloneProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //工作流的核心对象 ProcessEngine buildProcessEngine = createStandaloneProcessEngineConfiguration.buildProcessEngine(); System.out.println(buildProcessEngine); } }
在Activiti中,在创建核心的流程引擎对象时会自动建表。如果程序正常执行,mysql会自动建库,然后创建23张表。
2.添加并制定配置文件
在Actiiti5中定制流程必定会操作到数据库,如果都像上面那样写一大段代码会非常麻烦,所以我们可以把数据库连接配置写入配置文件。
创建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"> <!-- ProcessEngineConfiguration createStandaloneProcessEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); createStandaloneProcessEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver"); createStandaloneProcessEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti0710?useUnicode=true&characterEncoding=utf8"); createStandaloneProcessEngineConfiguration.setJdbcUsername("root"); /** public static final String DB_SCHEMA_UPDATE_FALSE = "false"; 不能自动创建表,需要表存在 public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop"; 表示先删除表,在创建表 public static final String DB_SCHEMA_UPDATE_TRUE = "true";如果表不存在,自动创建表 */ createStandaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(createStandaloneProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //工作流的核心对象 ProcessEngine buildProcessEngine = createStandaloneProcessEngineConfiguration.buildProcessEngine(); --> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"> <!-- 连接数据库配置 --> <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti0710?useUnicode=true&characterEncoding=utf8"></property> <property name="jdbcUsername" value="root"></property> <!-- 没有表创建表 --> <property name="databaseSchemaUpdate" value="true"></property> </bean> </beans>
java代码:
/** * 使用配置文件创建工作流需要的23张表 */ @Test public void createTable_2() { ProcessEngineConfiguration createProcessEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); ProcessEngine buildProcessEngine = createProcessEngineConfigurationFromResource.buildProcessEngine(); System.out.println(buildProcessEngine); }
以上是关于Activiti学习记录的主要内容,如果未能解决你的问题,请参考以下文章