最近公司要封装一套bpm工作流,选择了开源的Activiti作为基础,于是我进行了很多关于Activiti的学习研究,这一段时间应该会一直发一些我的学习研究成果,
希望能给一些人提供一些帮助。
好,废话不多说进入正题。我选用了Activiti5.22版本,准备使用SSM框架,这就涉及到了Activiti和Spring的集成,我创建了一个spring-activiti.xml文件,文件内容如下
<?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="cnpcbpmDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!--此处省略,数据源请自行配置-->
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="cnpcbpmDataSource" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="cnpcbpmDataSource" /> <property name="transactionManager" ref="transactionManager" /> <property name="databaseSchemaUpdate" value="true" /> <property name="jobExecutorActivate" value="true" /> </bean> <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" /> <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /> <bean id="formService" factory-bean="processEngine" factory-method="getFormService" /> <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /> <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" /> <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" /> </beans>
这样,我们就能通过Spring来获取Activiti的各种Service,从而能够进行各种需要的操作。
还有可以直接用代码就可以获得各个Service进行各种操作,由于在研究阶段,我都是用的这种方法。
ProcessEngineConfiguration pec=ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration(); pec.setJdbcDriver(""); pec.setJdbcUrl(""); pec.setJdbcUsername(""); pec.setJdbcPassword(""); /** * DB_SCHEMA_UPDATE_FALSE 不能自动创建表,需要表存在 * create-drop 先删除表再创建表 * DB_SCHEMA_UPDATE_TRUE 如何表不存在,自动创建和更新表 */ pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); ProcessEngine processEngine=pec.buildProcessEngine();
这样拿到引擎processEngine,就可以get各种service。执行此段代码后,数据库会有25张表存在,下面分析一下这些表的关系。
网上有一篇很好的表结构说明,地址 http://blog.csdn.net/claram/article/details/73277358
下一篇将具体讲述各个表的作用。