Activiti与SpringBoot项目整合

1.添加activiti-spring-boot-starter-basic依赖

		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-spring-boot-starter-basic</artifactId>
			<version>5.21.0</version>
		</dependency>

2.编写ActivitiConfig类

         配置 org.activiti.spring.SpringProcessEngineConfiguration类注入数据源和事务模板管理事务

@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {

	// 注入数据源和事务管理器
	@Bean
	public SpringProcessEngineConfiguration springProcessEngineConfiguration(
			@Qualifier("dataSourceSyDev") DataSource dataSource,
			@Qualifier("transactionManager") PlatformTransactionManager transactionManager,
			SpringAsyncExecutor springAsyncExecutor) throws IOException {
		return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
	}
}

3.编写ActivitiTest进行部署测试。

    注:(若不指定路径,默认去资源目录下的processes文件夹寻找xxx.bpmn和xxx.png资源部署)
@RunWith(SpringRunner.class)
@SpringBootTest
public class ActivitiTest {
	@Autowired
	private RepositoryService repositoryService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private IdentityService identityService;
	@Autowired
	private TaskService taskService;
	@Autowired
	private HistoryService historyService;
	@Autowired
	private ProcessEngineConfigurationImpl processEngineConfiguration;

	/**
	 * 布置流程 (操作数据表 act_re_deployment,act_re_procdef,act_ge_bytearray
	 * 
	 */
	@Test
	public void createDeployment() {
		DeploymentBuilder builder = repositoryService.createDeployment();
		builder.addClasspathResource("processes/MyProcess.bpmn");
		builder.addClasspathResource("processes/MyProcess.png");
		Deployment deploy = builder.deploy();
		System.out.println("布署id=" + deploy.getId());
	}
}

4.zip方式进行动态部署

/**
	 * 部署流程定义使用zip方式 (操作数据表 act_re_deployment,act_re_procdef,act_ge_bytearray
	 * 
	 */
	@Test
	public void createDeploymentByZip() {
		
		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("processes/MyProcess.zip"); // 获取指定文件资源流

		ZipInputStream zipInputStream = new ZipInputStream(inputStream); // 实例化zip输入流对象

		// 获取部署对象
		Deployment deployment = repositoryService.createDeployment() // 创建部署
				.name("审批流程") // 流程名称
				.addZipInputStream(zipInputStream) // 添加zip是输入流
				.deploy(); // 部署
		System.out.println("流程部署ID=" + deployment.getId() + ",流程部署Name=" + deployment.getName());
	}




展开阅读全文

没有更多推荐了,返回首页