最近在学习activity工作流, 将学习的点滴记录起来。
1、构建maven项目,导入activity包,在mysql数据库生成25张表。
是pom.xml配置,
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.19.0.2</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.19.0.2</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>5.19.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
2、生成数据库的表。
package com.activity;
import org.activiti.engine.ProcessEngineConfiguration;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
//工作流配置对象
ProcessEngineConfiguration pe = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
pe.setJdbcDriver("com.mysql.jdbc.Driver"); //mysql 的驱动
pe.setJdbcUrl("jdbc:mysql://localhost:3306/activity?useUnicode=true&characterEncoding=utf8"); //url地址
pe.setJdbcUsername("root");
pe.setJdbcPassword("123456");
//参数可以直接写true
pe.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//构建引擎流程的对象,创建表
pe.buildProcessEngine();
System.out.println( "Hello World!" );
}
}
2.(2)这是配置文件获取引擎的方式
<?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
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.xsd">
<!-- activiti流程引擎 -->
<!-- 流程引擎配置 -->
<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/activity" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="123456" />
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
执行代码:
package com.activity;
import org.activiti.engine.ProcessEngineConfiguration;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
/* //工作流配置对象
ProcessEngineConfiguration pe = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
pe.setJdbcDriver("com.mysql.jdbc.Driver"); //mysql 的驱动
pe.setJdbcUrl("jdbc:mysql://localhost:3306/activity?useUnicode=true&characterEncoding=utf8");
pe.setJdbcUsername("root");
pe.setJdbcPassword("123456");
pe.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//获取流程引擎对象
pe.buildProcessEngine();
System.out.println( "Hello World!" );*/
//试试配置文件
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activity/spring-activiti.xml");
configuration.buildProcessEngine();
}
}
配置数据可以配置在配置文件里,
3、执行代码生成数据表