一起看官方文档 —— Activiti(2)
2019-08-19 本文已影响0人
viankoo
序言
工作流框架基本上是每个比较复杂的OA或ERP系统的标配,同时Activiti又是国内使用最普遍的工作流框架。于是就想着把Activiti整理一下。
由于现在的项目越来越多的使用springboot,因为它太好用了,正如官方所说'开箱即用',零配置,敏捷开发的利器啊。应运而生,activiti-spring这样的插件就出现了。注意事项:使用activiti-spring一定要注意与springboot的适配,下面推荐的版本经试验无误。
Spring Boot 2.0 集成 Activiti 6.0
废话不多说上代码:
1、pom.xml
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>6.0.0</version>
</dependency>
2、新建activiti配置文件ActivitiConfig.java
@Configuration
public class ActivitiConfiguration {
@Autowired
private DataSource dataSource;
@Autowired
private PlatformTransactionManager platformTransactionManager;
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(){
SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration();
spec.setDataSource(dataSource);
spec.setTransactionManager(platformTransactionManager);
spec.setDatabaseSchemaUpdate("true");
// 启动自动部署流程
Resource[] resources = null;
try {
resources = new PathMatchingResourcePatternResolver().getResources("classpath*:bpmn/*.bpmn");
} catch (IOException e) {
e.printStackTrace();
}
spec.setDeploymentResources(resources);
return spec;
}
@Bean
public ProcessEngineFactoryBean processEngine(){
ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
processEngineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration());
return processEngineFactoryBean;
}
@Bean
public RepositoryService repositoryService() throws Exception{
return processEngine().getObject().getRepositoryService();
}
@Bean
public RuntimeService runtimeService() throws Exception{
return processEngine().getObject().getRuntimeService();
}
@Bean
public TaskService taskService() throws Exception{
return processEngine().getObject().getTaskService();
}
@Bean
public HistoryService historyService() throws Exception{
return processEngine().getObject().getHistoryService();
}
}
集成完毕!