工作流:
就是业务过程的部分或整体在计算机应用环境下的自动化,主要解决的是“在使用多个参与者之间按照某种预定义的规则传递文档,信息或任务的自动进行,从而实现某个与其的业务目标,或者促使此目标的实现。
工作流管理系统是一个软件系统,完成工作量的定义和管理,并按照系统中预先定义好的工作流逻辑进行工作流实例的执行。
常见的工作流框架:activiti5.13、JBPM4.4、OSWorkflow
工作流框架底层是有一套数据库提供支持的,针对不同的数据库提供不同的sql建表语句。Activiti5.13框架对应23张表,JBPM4.4框架对应18张表。开发人员不需要自己编写sql操作这些表的,框架底层会生成sql操作。Activiti框架底层使用mybatis操作数据库,JBPM框架底层使用hibernate操作数据库。
使用activiti自动建表:
1.没有提供xml配置文件
/**
* 使用activiti框架提供的自动建表方式创建23张表-----没有提供配置文件
*/
@Test
public void test1() {
// 创建一个流程引擎配置对象
ProcessEngineConfiguration conf = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
// 设置jdbc连接参数
conf.setJdbcDriver("com.mysql.jdbc.Driver");
conf.setJdbcUrl("jdbc:mysql:///activiti");
conf.setJdbcUsername("root");
conf.setJdbcPassword("root");
// 设置自动建表
conf.setDatabaseSchemaUpdate("true");
// 使用配置对象创建一个流程引擎对象,创建过程中可以自动建表
ProcessEngine processEngine = conf.buildProcessEngine();
}
2.提供xml文件
@Test
public void test2() {
ProcessEngineConfiguration conf = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource(
"activiti-context.xml", "processEngineConfiguration");
ProcessEngine processEngine = conf.buildProcessEngine();
}
配置文件:
<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="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///zjs_bos"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="root"></property>
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
<!-- 配置一个流程引擎工厂bean,用于创建流程引擎对象 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"></property>
</bean>
</beans>
3.使用默认配置文件
要求配置文件必须在类路径的根路径下,配置文件的名称必须为activiti-context.xml或者为activiti.cfg.xml,xml配置文件中必须配置流程引擎配置对象,id必须为processEngineConfiguration,必须配置流程引擎工厂bean,id必须为processEngine
@Test
public void test3() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
}