1.pom.xml
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.22.0</version>
</dependency>
2. resources目錄下新建processes文件夾放一個xxx.bpmn流程文件
3. java config方式配置:config.activiti下新建一個類ActivitiConfig:
package com.yunchuang.config.activiti;
import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.io.IOException;
/**
* activiti配置文件
* AbstractProcessEngineAutoConfiguration在activiti-spring-boot-starter-basic下
*
* @author 尹冬飛
* @create 2017-04-10 10:30
*/
@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {
static final String NAME = "master";
//注入數(shù)據(jù)源和事務管理器
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(
@Qualifier(NAME + "DataSource") DataSource dataSource,
@Qualifier(NAME + "TransactionManager") PlatformTransactionManager transactionManager,
SpringAsyncExecutor springAsyncExecutor) throws IOException {
return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
}
}
4.這樣就可以直接調用相關的service了.測試代碼:
package com.yunchuang;
import org.activiti.engine.RuntimeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Demo8ApplicationTests {
@Autowired
RuntimeService runtimeService;
@Test
public void contextLoads() {
long count = runtimeService.createProcessInstanceQuery()
.count();
System.out.println(count);
}
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者