版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ip_JL/article/details/83500961
简介
工作流: 业务过程的部分或整体在计算机应用环境下的自动化,使在多个参与者之间按照某种预定义的规则传递文档、信息或任务的过程自动进行,从而实现某个预期的业务目标
工作流系统:
它是一个软件系统,它完成工作量的定义和管理,并按照在系统中预先定义好的工作流规则进行工作流实例的执行。工作流管理系统不是企业的业务系统,而是为企业的业务系统的运行提供了一个软件的支撑环境。
环境搭建
1)新建一个Activiti的工程
引包:链接:https://pan.baidu.com/s/1JI9n9UG_76dzllLDHRwulw 提取码:akvs
2)测试代码①:
@Test
public void testProcessWithCode() {
//创建流程引擎配置对象
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
//配置mysql数据库的连接
processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.Driver");
processEngineConfiguration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti01");
processEngineConfiguration.setJdbcUsername("root");
processEngineConfiguration.setJdbcPassword("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"; ===> 启动引擎时, 如果数据库中有表, 则不建表; 如果没表, 则建表; 关闭引擎时不删表; 如果sql有更新, 引擎再次启动时会更新数据库中的表
*/
processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//创建流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
System.out.println(processEngine);
}
②:
先配置好‘activiti-cfg-context.xml’文件, 放在classpath下:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/activiti01"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="root"></property>
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
</beans>
此时的测试代码如下:
@Test
public void testProcessWithXMLConfig() {
//创建流程引擎配置对象
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti-cfg-context.xml");
//创建流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
System.out.println(processEngine);
}
已经自动建好数据库表:
至此, Activiti工作流的环境搭建完成.