Activiti与Springboot整合
在Spring Boot与Activiti整合时,通常使用activiti-spring-boot-starter
来简化配置。以下是一个基本的示例:
- 添加依赖到
pom.xml
:
<dependencies>
<!-- Activiti Spring Boot Starter -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M6</version>
</dependency>
<!-- Spring Boot Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- Spring Boot Starter Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
- 配置
application.properties
或application.yml
:
# Database configuration for Activiti
spring.datasource.url=jdbc:mysql://localhost:3306/activiti?useSSL=false
spring.datasource.username=root
spring.datasource.password=example
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Activiti specific configuration
spring.activiti.database-schema-update=true
spring.activiti.check-process-definitions=false
- 创建Spring Boot启动类:
@SpringBootApplication
public class ActivitiSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(ActivitiSpringBootApplication.class, args);
}
}
- 使用Activiti API:
@Service
public class ActivitiService {
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
public void deployProcess(String processName, String resource) {
repositoryService.createDeployment()
.addClasspathResource(resource)
.deploy();
}
public void startProcessInstance(String processKey) {
runtimeService.startProcessInstanceByKey(processKey);
}
public List<Task> getMyTasks(String assignee) {
return taskService.createTaskQuery().taskAssignee(assignee).list();
}
}
以上代码展示了如何在Spring Boot应用程序中使用Activiti。首先,通过\`activiti-sprin
评论已关闭