将Activiti7整合进入SpringBoot中,而不使用官方提供的activiti-spring-boot-starter。
一、POM引入Activiti依赖
文件名:pom.xml
类型:Maven项目配置
作用:引入Activiti7库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <properties> <activiti.version>7.1.0.M6</activiti.version> </properties>
<dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${activiti.version}</version> </dependency>
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${activiti.version}</version> </dependency>
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-model</artifactId> <version>${activiti.version}</version> </dependency>
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-converter</artifactId> <version>${activiti.version}</version> </dependency>
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-json-converter</artifactId> <version>${activiti.version}</version> </dependency>
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-layout</artifactId> <version>${activiti.version}</version> </dependency> </dependencies>
|
二、注册Activiti相关的Bean
文件名:ApplicationConfiguration.java
类型:Spring配置注解
作用:注册ServiceBean需要使用的SpringProcessEngineConfiguration和ProcessEngineFactoryBean
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import org.activiti.spring.ProcessEngineFactoryBean; import org.activiti.spring.SpringProcessEngineConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.sql.DataSource;
@Configuration @Order(300) public class ApplicationConfiguration { private Logger logger = LoggerFactory.getLogger(ApplicationConfiguration.class); private DataSource dataSource; private PlatformTransactionManager transactionManager;
public ApplicationConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) { this.dataSource = dataSource; this.transactionManager = transactionManager; }
@Bean public SpringProcessEngineConfiguration processEngineConfiguration() { logger.info("注册Activiti流程引擎配置……"); SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration(); springProcessEngineConfiguration.setDataSource(dataSource); springProcessEngineConfiguration.setTransactionManager(transactionManager); springProcessEngineConfiguration.setDatabaseSchemaUpdate("true"); return springProcessEngineConfiguration; }
@Bean public ProcessEngineFactoryBean processEngine() { logger.info("注册Activiti流程引擎……"); ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean(); processEngineFactoryBean.setProcessEngineConfiguration(processEngineConfiguration()); return processEngineFactoryBean; } }
|
文件名:ActivitiConfiguration.java
类型:Spring配置注解
作用:注册各个ServiceBean,其中的Order注解确保在ProcessEngineBean被创建之后再执行此配置中各种服务Bean的创建。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import org.activiti.engine.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order;
@Configuration @Order(301) public class ActivitiConfiguration { private Logger logger = LoggerFactory.getLogger(ActivitiConfiguration.class); private ProcessEngine processEngine;
public ActivitiConfiguration(ProcessEngine processEngine) { this.processEngine = processEngine; }
@Bean public RepositoryService repositoryService() { logger.info("注册Activiti资源服务……"); return processEngine.getRepositoryService(); }
@Bean public RuntimeService runtimeService() { logger.info("注册Activiti运行时服务……"); return processEngine.getRuntimeService(); }
@Bean public TaskService taskService() { logger.info("注册Activiti任务服务……"); return processEngine.getTaskService(); }
@Bean public HistoryService historyService() { logger.info("注册Activiti历史服务……"); return processEngine.getHistoryService(); } }
|
以上。