学习分别通过代码和Spring注入的方式创建Activiti数据表(共23张表)
一、Java代码:
package com.steven.activiti;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
/**
* Activiti学习入门
*
* @author Steven 2015年 下午11:36:39
*/
public class TestActiviti {
/**
* 通过代码的方式创建Activiti数据表(共23张表)
*/
@Test
public void createTableByCode() {
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
// 连接数据库的配置
processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
processEngineConfiguration
.setJdbcUrl("jdbc:mysql://localhost:3306/StevenActiviti?useUnicode=true&characterEncoding=utf8");
processEngineConfiguration.setJdbcUsername("root");
processEngineConfiguration.setJdbcPassword("");
// Activiti的23个表不存在则自动创建
processEngineConfiguration
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
// 工作流的核心对象,ProcessEnginee对象
ProcessEngine processEngine = processEngineConfiguration
.buildProcessEngine();
System.out.println("创建ProcessEnginee对象成功:" + processEngine);
}
/**
* 通过Spring注入的方式创建Activiti数据表(共23张表)
*/
@Test
public void createTablesBySpring() {
ProcessEngine processEngine = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource(
"activiti.cfg.xml") //
.buildProcessEngine();
System.out.println("创建ProcessEnginee对象成功:" + processEngine);
}
}
<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/StevenActiviti?useUnicode=true&characterEncoding=utf8"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value=""></property>
<!-- 没有表创建表 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
</beans>