当前位置:网站首页>【activiti】activiti流程引擎配置类
【activiti】activiti流程引擎配置类
2022-07-24 05:19:00 【你怎么不笑了】
activiti流程引擎配置类
1.流程引擎配置类
流程引擎的配置类:ProcessEngineConfiguration,通过ProcessEngineConfiguration可以创建工作流引擎ProcessEngine,常用的两种方法如下:
1.1StandaloneProcessEngineConfiguration
使用StandaloneProcessEngineConfigurationActiviti可以单独运行,来创建ProcessEngine,Activiti会自己处理事务。
配置文件方式:通常在activiti.cfg.xml配置文件中定义一个id为processEngineConfiguration的bean
如:
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--配置数据库相关的信息-->
<!--数据库驱动-->
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
<!--数据库链接-->
<property name="jdbcUrl" value="jdbc:mysql:///activiti"/>
<!--数据库用户名-->
<property name="jdbcUsername" value="root"/>
<!--数据库密码-->
<property name="jdbcPassword" value="root"/>
<!--actviti数据库表在生成时的策略 true - 如果数据库中已经存在相应的表,那么直接使用,如果不存在,那么会创建-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
或者加入连接池的方式:
<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/activiti"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!--在默认方式下 bean的id 固定为 processEngineConfiguration-->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--引入上面配置好的 链接池-->
<property name="dataSource" ref="dataSource"/>
<!--actviti数据库表在生成时的策略 true - 如果数据库中已经存在相应的表,那么直接使用,如果不存在,那么会创建-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
1.2.SpringProcessEngineConfiguration
通过org.activiti.spring.SpringProcessEngineConfiguration与spring整合
创建spring与activiti的整合配置文件:
activiti-spring.cfg.xml(名字可更改)
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
<!-- 工作流引擎配置bean -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 使用spring事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<!-- 数据库策略 -->
<property name="databaseSchemaUpdate" value="drop-create" />
<!-- activiti的定时任务关闭 -->
<property name="jobExecutorActivate" value="false" />
</bean>
<!-- 流程引擎 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<!-- 资源服务service -->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<!-- 流程运行service -->
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<!-- 任务管理service -->
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<!-- 历史管理service -->
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<!-- 用户管理service -->
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
<!-- 引擎管理service -->
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/activiti" />
<property name="username" value="root" />
<property name="password" value="mysql" />
<property name="maxActive" value="3" />
<property name="maxIdle" value="1" />
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes></tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 切面,根据具体项目修改切点配置 -->
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.itheima.ihrm.service.impl.*.(..))"* />
</aop:config>
</beans>
2.创建processEngineConfiguration
方法一:要求activiti.cfg.xml中必须有一个processEngineConfiguration的bean
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml")
方法二:可以更改bean名称
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);
3.创建工作流引擎processEngine
工作流引擎:ProcessEngine,相当于一个门面接口,通过ProcessEngineConfiguration创建ProcessEngine,然后通过ProcessEngine来创建各个service接口
3.1默认创建方式
在固定的路径resource下创建配置文件activiti.cfg.xml,xml文件有processEngineConfiguration的配置,然后使用下面的代码创建processEngine:
//直接使用工具类 ProcessEngines,使用classpath下的activiti.cfg.xml中的配置创建processEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println(processEngine);
3.2一般创建方式
//先构建ProcessEngineConfiguration
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//通过ProcessEngineConfiguration创建ProcessEngine,此时会创建数据库
ProcessEngine processEngine = configuration.buildProcessEngine();
4.Service服务接口
Service是工作流引擎提供用于进行工作流部署、执行、管理的服务接口,使用这些服务类就可以操作服务对应的数据表
4.1Service创建方式
通过ProcessEngine创建Service
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
4.2Service总览
| service名称 | service作用 |
|---|---|
| RepositoryService | activiti的资源管理类 |
| RuntimeService | activiti的流程运行管理类 |
| TaskService | activiti的任务管理类 |
| HistoryService | activiti的历史管理类 |
| ManagerService | activiti的引擎管理类 |
边栏推荐
- Flink Format系列(1)-JSON
- 【mycat】mycat介绍
- Insanity:1(Insanity-Hosting)靶机渗透 —Vulnhub
- Three -- orbitcontrols track controller
- Whole station downloader recommendation
- 4. Draw a red triangle and a yellow square on the screen. Triangle in the back, small; Square in front, big. Using the fusion technology, the triangle can be seen through the square, and the source an
- Create a new UMI project, error: rendered more hooks or rendered fewer hooks
- 【mycat】mycat配置文件
- mysqldump 导出中文乱码
- Development technical guide | the most complete technical documents, tutorials and courses of substrate and Polkadot
猜你喜欢
随机推荐
haclabs: no_ Name (hl.ova) target penetration vulnhub
【mycat】mycat相关概念
Sunset: noontide target penetration vulnhub
Whole station downloader recommendation
第五届 Polkadot Hackathon 创业大赛全程回顾,获胜项目揭秘!
Flink task, sub task, task slot and parallelism
【mycat】mycat分库分表
公司女同事深夜11点让我去她住处修电脑,原来是C盘爆红,看我一招搞定女同事....的电脑
Oracle数据库的逻辑结构
网页播放rtsp视频流
XML之建模
php的多选、单选结果怎么在前台显示?
Function Closure
波卡创始人 Gavin Wood:波卡治理 v2 会有哪些变化?
Flink函数(2):CheckpointedFunction
Variables and constants in C language
Analysis of logic development principle of quantitative contract clip arbitrage robot system
数据仓库与数仓建模
【vsphere高可用】主机和虚拟机故障监测工作原理
Wechat applet reports an error request:fail -2:net:: err_ FAILED









