Activiti 7 集成概述
Activiti流程引擎是BPMN开源产品中做得比较优秀的产品,经历了jbpm3,jbpm4,activiti5,activiti6的几代产品迭代,目前推出针对单体应用与云应用的activiti7,重构了原有的pvm的流程引擎机制,让流程执行效率更优,平台集成activiti7,只是使用了其流程定义与流程实例,流程待办的几块特性外,大部分进行了业务外围特性的扩展,同时保留了Activiti的其他引擎能力。
依赖导入
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M6</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-image-generator</artifactId>
<version>7.1.0.M6</version>
</dependency>
SpringBoot中引擎配置入口
package com.redxun.bpm.config;
import com.redxun.bpm.activiti.event.GlobalEventListener;
import com.redxun.bpm.activiti.ext.FlowDefCache;
import com.redxun.bpm.activiti.ext.RxIdGenerator;
import com.redxun.bpm.activiti.img.ActivitiDiagramGenerator;
import com.redxun.datasource.DataSourceUtil;
import org.activiti.api.runtime.shared.identity.UserGroupManager;
import org.activiti.engine.cfg.ProcessEngineConfigurator;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory;
import org.activiti.image.ProcessDiagramGenerator;
import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.activiti.spring.boot.ActivitiProperties;
import org.activiti.spring.boot.DefaultActivityBehaviorFactoryMappingConfigurer;
import org.activiti.spring.boot.process.validation.AsyncPropertyValidator;
import org.activiti.validation.ProcessValidatorImpl;
import org.activiti.validation.validator.ValidatorSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* Activiti流程引擎构建配置入口
* @author csx
* @since 1.0
*/
@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {
@Bean
@Primary
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
PlatformTransactionManager transactionManager,
SpringAsyncExecutor springAsyncExecutor,
ActivitiProperties activitiProperties,
@Autowired(required = false) DefaultActivityBehaviorFactoryMappingConfigurer processEngineConfigurationConfigurer,
@Autowired(required = false) List<ProcessEngineConfigurator> processEngineConfigurators,
UserGroupManager userGroupManager,
@Qualifier(DataSourceUtil.GLOBAL_DATASOURCE) DataSource dataSource) throws IOException {
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();
conf.setConfigurators(processEngineConfigurators);
//设置数据源
conf.setDataSource(dataSource);
//设置全局事务管理器
conf.setTransactionManager(transactionManager);
if (springAsyncExecutor != null) {
conf.setAsyncExecutor(springAsyncExecutor);
}
//设置发布名
conf.setDeploymentName(activitiProperties.getDeploymentName());
conf.setDatabaseSchema(activitiProperties.getDatabaseSchema());
conf.setDatabaseSchemaUpdate(activitiProperties.getDatabaseSchemaUpdate());
conf.setDbHistoryUsed(activitiProperties.isDbHistoryUsed());
conf.setAsyncExecutorActivate(activitiProperties.isAsyncExecutorActivate());
if (!activitiProperties.isAsyncExecutorActivate()) {
ValidatorSet springBootStarterValidatorSet = new ValidatorSet("activiti-spring-boot-starter");
springBootStarterValidatorSet.addValidator(new AsyncPropertyValidator());
if (conf.getProcessValidator() == null) {
ProcessValidatorImpl processValidator = new ProcessValidatorImpl();
processValidator.addValidatorSet(springBootStarterValidatorSet);
conf.setProcessValidator(processValidator);
} else {
conf.getProcessValidator().getValidatorSets().add(springBootStarterValidatorSet);
}
}
//设置邮件发送配置
conf.setMailServerHost(activitiProperties.getMailServerHost());
conf.setMailServerPort(activitiProperties.getMailServerPort());
conf.setMailServerUsername(activitiProperties.getMailServerUserName());
conf.setMailServerPassword(activitiProperties.getMailServerPassword());
conf.setMailServerDefaultFrom(activitiProperties.getMailServerDefaultFrom());
conf.setMailServerUseSSL(activitiProperties.isMailServerUseSsl());
conf.setMailServerUseTLS(activitiProperties.isMailServerUseTls());
if (userGroupManager != null) {
conf.setUserGroupManager(userGroupManager);
}
conf.setHistoryLevel(activitiProperties.getHistoryLevel());
conf.setCopyVariablesToLocalForTasks(activitiProperties.isCopyVariablesToLocalForTasks());
conf.setSerializePOJOsInVariablesToJson(activitiProperties.isSerializePOJOsInVariablesToJson());
conf.setJavaClassFieldForJackson(activitiProperties.getJavaClassFieldForJackson());
if (activitiProperties.getCustomMybatisMappers() != null) {
conf.setCustomMybatisMappers(
getCustomMybatisMapperClasses(activitiProperties.getCustomMybatisMappers()));
}
if (activitiProperties.getCustomMybatisXMLMappers() != null) {
conf.setCustomMybatisXMLMappers(
new HashSet<>(activitiProperties.getCustomMybatisXMLMappers()));
}
if (activitiProperties.getCustomMybatisXMLMappers() != null) {
conf.setCustomMybatisXMLMappers(
new HashSet<>(activitiProperties.getCustomMybatisXMLMappers()));
}
//设置其Id产生器
conf.setIdGenerator(new RxIdGenerator());
if (activitiProperties.getDeploymentMode() != null) {
conf.setDeploymentMode(activitiProperties.getDeploymentMode());
}
conf.setActivityBehaviorFactory(new DefaultActivityBehaviorFactory());
if (processEngineConfigurationConfigurer != null) {
processEngineConfigurationConfigurer.configure(conf);
}
//加上全局事件的控制
List<ActivitiEventListener> eventListeners=new ArrayList<>();
eventListeners.add(new GlobalEventListener());
conf.setEventListeners(eventListeners);
//修改其流程缓存
conf.setProcessDefinitionCache(new FlowDefCache());
return conf;
}
@Override
@Primary
@Bean
public TaskExecutor taskExecutor(){
return new SyncTaskExecutor();
}
@Bean
public ProcessDiagramGenerator activitiDiagramGenerator(){
return new ActivitiDiagramGenerator();
}
}
在application.yml配置数据源
defaultDs:
string:
# url: jdbc:dm://localhost:5236/JPAASBPM?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
# username: JPAASBPM
# password: JPAASBPM
# driver-class-name: dm.jdbc.driver.DmDriver
# connection-init-sqls: SET SCHEMA JPAASBPM
#url: ${bpm.datasource.url}://${bpm.datasource.ip}:${bpm.datasource.port}/${bpm.datasource.name}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8
url: ${bpm.datasource.url}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8
username: ${bpm.datasource.username}
password: ${bpm.datasource.password}
driver-class-name: ${bpm.datasource.driver}
connection-init-sqls: ${bpm.datasource.connection}
validationQuery: select 1
filters: stat
int:
initialSize: 5
minIdle: 5
maxActive: 10
maxPoolPreparedStatementPerConnectionSize: 20
long:
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
boolean:
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
mybatis:
mapper-locations: classpath:/mapper/**/*Mapper.xml
在application.yml引入seata支持分布式事务
seata:
enabled: true
application-id: ${spring.application.name}
tx-service-group: bpm_tx_group
enable-auto-data-source-proxy: true
registry:
type: nacos
nacos:
application: seata-server
server-addr: ${nacos.address}
group: DEFAULT_GROUP
userName: nacos
password: nacos
config:
type: nacos
nacos:
namespace:
serverAddr: ${nacos.address}
group: SEATA_GROUP
cluster: default
userName: nacos
password: nacos
在业务服务类中使用Activiti服务类
@Service
public class ActRepService {
@Resource
RepositoryService repositoryService;
@Resource
ManagementService managementService;
@Resource
RuntimeService runtimeService;
@Resource
TaskService taskService;
}
文档更新时间: 2020-10-12 09:25 作者:csx