springboot.2.x 与Spring 集成activiti 的区别

java哥 阅读:678 2021-03-31 16:56:06 评论:0

springboot 2.x 集成activiti 6.0 ,通过activiti-spring-boot-start-basic-*.jar 完成SpringProcessEngineConfiguration.java(流程引擎配置参数) 、ProcessEngine(流程引擎).java 、RepositoryService(部署对象实例化).java、RuntimeService(运行对象实例化).java、TaskService(运行对象实例化).java、HistoryService(历史任务对象实例化).java、FormService( 表单对象实例化).java 。

相关说明类如下:

org.activiti.spring.boot.ActivitiProperties.java =springboot 关于 activiti 的配置参数

org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration、DataSourceProcessEngineConfiguration=等待DataSourceAutoConfiguration.class加载完毕,自动注入DataSource数据源 和 PlatformTransactionManager事务管理器。

相关流程如下截图:

如果是spring 集成activiti 就需要添加如下代码:

package com.zzg.activiti.config; 
 
import javax.sql.DataSource; 
 
import org.activiti.engine.FormService; 
import org.activiti.engine.HistoryService; 
import org.activiti.engine.ProcessEngine; 
import org.activiti.engine.RepositoryService; 
import org.activiti.engine.RuntimeService; 
import org.activiti.engine.TaskService; 
import org.activiti.spring.ProcessEngineFactoryBean; 
import org.activiti.spring.SpringProcessEngineConfiguration; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.transaction.PlatformTransactionManager; 
/** 
 * activiti 流程配置 
 * @author zzg 
 * 
 */ 
@Configuration 
public class ActivitiConfig { 
	 
	// 日志管理 
	private Logger logger = LoggerFactory.getLogger(ActivitiConfig.class); 
	 
	 
	@Autowired 
	private DataSource dataSource; 
	 
	@Autowired 
	private PlatformTransactionManager transactionManager; 
	 
	/** 
	 * activiti 处理引擎配置参数实列化对象 
	 * @return 
	 */ 
	@Bean 
	public SpringProcessEngineConfiguration processEngineConfig(){ 
		SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration(); 
		// 数据源设置 
		processEngineConfiguration.setDataSource(dataSource); 
		// 事务管理器 
		processEngineConfiguration.setTransactionManager(transactionManager); 
		return processEngineConfiguration; 
	} 
	 
	/** 
	 * activiti 处理引擎实列化对象 
	 * @return 
	 */ 
	@Bean 
	public ProcessEngine processEngine(){ 
		ProcessEngine processEngine= null; 
		ProcessEngineFactoryBean factory = new ProcessEngineFactoryBean(); 
		factory.setProcessEngineConfiguration(processEngineConfig()); 
		try { 
			processEngine = factory.getObject(); 
		} catch (Exception e) { 
			// TODO Auto-generated catch block 
			logger.error(e.getMessage()); 
			return null; 
		} 
		return processEngine; 
	} 
	/** 
	 * activiti 部署对象实例化 
	 */ 
	@Bean 
	public RepositoryService getRepository(){ 
		return processEngine().getRepositoryService(); 
	} 
	 
	/** 
	 * activiti 运行对象实例化 
	 */ 
	@Bean 
	public RuntimeService getRuntime(){ 
		return processEngine().getRuntimeService(); 
	} 
	 
	/** 
	 * activiti 任务对象实例化 
	 */ 
	@Bean 
	public TaskService getTask(){ 
		return processEngine().getTaskService(); 
	} 
	 
	/** 
	 * activiti 历史任务对象实例化 
	 * @return 
	 */ 
	@Bean 
	public HistoryService getHistory(){ 
		return processEngine().getHistoryService(); 
	} 
	 
	/** 
	 * activiti 表单对象实例化 
	 * @return 
	 */ 
	@Bean 
	public FormService getForm(){ 
		return processEngine().getFormService(); 
	} 
	 
	 
	 
	 
 
} 

功能流程上无太多区别,只是一个是自动注入另一种方式是硬编码。

标签:Spring Boot
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号