配置事务
初始化配置
@Configuration
@AllArgsConstructor
public class ActivitiConfig {
private final DataSource dataSource;
private final PlatformTransactionManager transactionManager;
@Bean
public SpringProcessEngineConfiguration getProcessEngineConfiguration() {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
// 流程图字体设置
config.setActivityFontName("宋体");
config.setAnnotationFontName("宋体");
config.setLabelFontName("黑体");
config.setDataSource(dataSource);
config.setTransactionManager(transactionManager);//配置事务管理类
config.setDatabaseType("mysql");//数据库类型
config.setDatabaseSchemaUpdate("true");
config.setEventListeners(Arrays.asList(new ProcessEventListener()));
return config;
}
@Bean
@Primary
public TaskExecutor primaryTaskExecutor() {
return new ThreadPoolTaskExecutor();
}
}
方法事务注解
@PostMapping("/startProcess")
@ApiOperation(value = "创建审批", notes = "创建审批")
@TxTransaction(isStart = false)
@Transactional
public R startProcess(@RequestBody BusinessDto dto) throws Exception {
commonBusinessService.saveStartProcess(dto);
return R.ok(true);
}
这里必须加入@Transactional和@TxTransaction两个注解,只加分布式事务@TxTransaction注解会导致其他分布式服务事务回滚,但工作流事务却没有回滚