pom.xml
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M6</version>
<!--这里解决activiti里面的mybatis和mybatis-plus包的冲突-->
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-image-generator</artifactId>
<version>7.1.0.M6</version>
</dependency>
去掉activiti自带的默认spring security权限校验
@Slf4j
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").permitAll();
http.headers().frameOptions().sameOrigin().httpStrictTransportSecurity().disable();
//post 403问题
http.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
}
yml文件:
spring:
# 参考配置https://www.cnblogs.com/liaojie970/p/8857710.html
activiti:
# 自动建表
# database-schema:
# flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常。(生产环境常用)
# true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建。(开发时常用)
# create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表)。(单元测试常用)
# drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎)。
database-schema-update: true
#记录历史等级 可配置的历史级别有none, activity, audit, full
history-level: full
#检测历史表是否存在
db-history-used: true
集成时候遇到的坑:
异常1:ACT_RU_EXECUTION删除异常(会签任务完成时异常)
delete from ACT_RU_EXECUTION where ID_ = '21696422-9a8e-11ea-87dd-1831bfdf48c6' and REV_ = 2
2020-05-20 19:37:35.625 ERROR --- [-nio-8888-exec-4] o.a.e.impl.interceptor.CommandContext 149 : Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`bossSit`.`ACT_RU_VARIABLE`, CONSTRAINT `ACT_FK_VAR_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`))
### The error may exist in org/activiti/db/mapping/entity/Execution.xml
### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
解决方法:
设置ACT_RU_VARIABLE表的ACT_FK_VAR_EXE外键,删除时为CASCADE。不知道是不是7的bug
异常2:多实例会签 nrOfCompletedInstances 变量始终为0,不会变的情况
解决:
1.每个usertask配置任务完成监听
<activiti:taskListener event="complete" delegateExpression="${taskSequentialListenerComplete}" />
2.然后在监听里修改值
代码:
@Data
@Slf4j
@Service
public class TaskSequentialListenerComplete implements TaskListener {
@Autowired
private TaskService taskService;
@Autowired
private RuntimeService runtimeService;
@Override
public void notify(DelegateTask task) {
/**
* 不知道是不是activiti7的bug,我是遇到了,这个值不会动,详见
* https://segmentfault.com/a/1190000019575655
*/
Integer completedInstances1 = task.getExecution().getParent().getVariable("nrOfCompletedInstances", Integer.class);
Integer nrOfActiveInstances1 = task.getExecution().getParent().getVariable("nrOfActiveInstances", Integer.class);
task.getExecution().setVariable("nrOfCompletedInstances", completedInstances1);
task.getExecution().setVariable("nrOfActiveInstances", nrOfActiveInstances1);
}
}
注意:多实例会签,结束条件-无论是串行还是并行,都是以结束条件为准。貌似不设置条件,是以全部执行完结束,最好是设置一下