SpringBoot 集成 activiti
基础环境搭建
添加依赖
<dependency>
<groupId>org.activiti
</groupId>
<artifactId>activiti-spring-boot-starter-basic
</artifactId>
<version>6.0.0
</version>
</dependency>
添加配置文件
server:
tomcat:
uri-encoding: UTF
-8
threads:
max: 1000
min-spare: 30
port: 8082
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc
:mysql
://127.0.0.1
:3306/activiti6
-demo
?characterEncoding=utf8
&useSSL=false
username: root
password: 123456
activiti:
database-schema-update: true
check-process-definitions: false
history-level: audit
db-history-used: true
现在运行项目报错
java
.lang
.IllegalArgumentException
: Could not find
class [org
.springframework
.boot
.autoconfigure
.security
.SecurityAutoConfiguration
]
at org
.springframework
.util
.ClassUtils
.resolveClassName(ClassUtils
.java
:334) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.core
.annotation
.TypeMappedAnnotation
.adapt(TypeMappedAnnotation
.java
:446) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.core
.annotation
.TypeMappedAnnotation
.getValue(TypeMappedAnnotation
.java
:369) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.core
.annotation
.TypeMappedAnnotation
.asMap(TypeMappedAnnotation
.java
:284) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.core
.annotation
.AbstractMergedAnnotation
.asAnnotationAttributes(AbstractMergedAnnotation
.java
:193) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.core
.type
.AnnotatedTypeMetadata
.getAnnotationAttributes(AnnotatedTypeMetadata
.java
:106) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.AnnotationConfigUtils
.attributesFor(AnnotationConfigUtils
.java
:285) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.AnnotationBeanNameGenerator
.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator
.java
:102) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.AnnotationBeanNameGenerator
.generateBeanName(AnnotationBeanNameGenerator
.java
:81) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.ConfigurationClassBeanDefinitionReader
.registerBeanDefinitionForImportedConfigurationClass(ConfigurationClassBeanDefinitionReader
.java
:160) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.ConfigurationClassBeanDefinitionReader
.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader
.java
:141) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.ConfigurationClassBeanDefinitionReader
.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader
.java
:120) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.ConfigurationClassPostProcessor
.processConfigBeanDefinitions(ConfigurationClassPostProcessor
.java
:331) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.annotation
.ConfigurationClassPostProcessor
.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor
.java
:236) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.support
.PostProcessorRegistrationDelegate
.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate
.java
:280) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.support
.PostProcessorRegistrationDelegate
.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate
.java
:96) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.support
.AbstractApplicationContext
.invokeBeanFactoryPostProcessors(AbstractApplicationContext
.java
:707) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.context
.support
.AbstractApplicationContext
.refresh(AbstractApplicationContext
.java
:533) ~[spring
-context
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.boot
.web
.servlet
.context
.ServletWebServerApplicationContext
.refresh(ServletWebServerApplicationContext
.java
:143) ~[spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.refresh(SpringApplication
.java
:758) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.refresh(SpringApplication
.java
:750) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.refreshContext(SpringApplication
.java
:397) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.run(SpringApplication
.java
:315) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.run(SpringApplication
.java
:1237) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at org
.springframework
.boot
.SpringApplication
.run(SpringApplication
.java
:1226) [spring
-boot
-2.3.4.RELEASE
.jar
:2.3.4.RELEASE
]
at com
.test
.activitydemo
.ActivityDemoApplication
.main(ActivityDemoApplication
.java
:11) [classes
/:na
]
Caused by
: java
.lang
.ClassNotFoundException
: org
.springframework
.boot
.autoconfigure
.security
.SecurityAutoConfiguration
at java
.net
.URLClassLoader
.findClass(URLClassLoader
.java
:382) ~[na
:1.8.0_191
]
at java
.lang
.ClassLoader
.loadClass(ClassLoader
.java
:424) ~[na
:1.8.0_191
]
at sun
.misc
.Launcher$AppClassLoader
.loadClass(Launcher
.java
:349) ~[na
:1.8.0_191
]
at java
.lang
.ClassLoader
.loadClass(ClassLoader
.java
:357) ~[na
:1.8.0_191
]
at java
.lang
.Class
.forName0(Native Method
) ~[na
:1.8.0_191
]
at java
.lang
.Class
.forName(Class
.java
:348) ~[na
:1.8.0_191
]
at org
.springframework
.util
.ClassUtils
.forName(ClassUtils
.java
:284) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
at org
.springframework
.util
.ClassUtils
.resolveClassName(ClassUtils
.java
:324) ~[spring
-core
-5.2.9.RELEASE
.jar
:5.2.9.RELEASE
]
... 25 common frames omitted
在启动类中排除安全配置就可以成功运行
@SpringBootApplication( exclude
= SecurityAutoConfiguration
.class)
public class ActivityDemoApplication {
public static void main(String
[] args
) {
SpringApplication
.run(ActivityDemoApplication
.class, args
);
}
}
idea 流程图插件
链接: https://pan.baidu.com/s/1UFSV1lfhVjc3eEdFCpTtxQ 密码: gw6s
简单的请假流程
画流程图
请假
package com
.test
.activitydemo
.a_first
;
import com
.test
.activitydemo
.ActivityDemoApplicationTests
;
import org
.activiti
.engine
.HistoryService
;
import org
.activiti
.engine
.RepositoryService
;
import org
.activiti
.engine
.RuntimeService
;
import org
.activiti
.engine
.TaskService
;
import org
.activiti
.engine
.history
.HistoricProcessInstance
;
import org
.activiti
.engine
.history
.HistoricTaskInstance
;
import org
.activiti
.engine
.repository
.Deployment
;
import org
.activiti
.engine
.runtime
.ProcessInstance
;
import org
.activiti
.engine
.task
.Task
;
import org
.junit
.jupiter
.api
.Test
;
import org
.springframework
.util
.CollectionUtils
;
import javax
.annotation
.Resource
;
import java
.util
.List
;
public class ActivitiQuick extends ActivityDemoApplicationTests {
@Resource
private RepositoryService repositoryService
;
@Resource
private RuntimeService runtimeService
;
@Resource
private TaskService taskService
;
@Resource
private HistoryService historyService
;
private final String bpmnNameAndKey
= "first";
@Test
public void createTable() {
}
@Test
public void deploy() {
Deployment deploy
= repositoryService
.createDeployment()
.addClasspathResource("processes/first.bpmn")
.key(bpmnNameAndKey
)
.name(bpmnNameAndKey
+ "name")
.category("HR")
.deploy();
System
.out
.println("流程部署ID\t" + deploy
.getId());
System
.out
.println("流程keyID\t" + deploy
.getKey());
System
.out
.println("流程名称ID\t" + deploy
.getName());
System
.out
.println("流程分类ID\t" + deploy
.getCategory());
}
@Test
public void start() {
ProcessInstance processInstance
= runtimeService
.startProcessInstanceByKey(bpmnNameAndKey
);
System
.out
.println("流程实例ID\t" + processInstance
.getId());
System
.out
.println("流程定义ID\t" + processInstance
.getProcessDefinitionId());
System
.out
.println("流程定义key\t" + processInstance
.getProcessDefinitionKey());
}
@Test
public void findMyTask() {
String assignee
= "李四";
List
<Task> list
= taskService
.createTaskQuery()
.taskAssignee(assignee
)
.list();
if (!CollectionUtils
.isEmpty(list
)) {
for (Task task
: list
) {
System
.out
.println("任务ID\t" + task
.getId());
System
.out
.println("任务名称\t" + task
.getName());
System
.out
.println("任务执行人\t" + task
.getAssignee());
}
}
}
@Test
public void complte() {
String taskId
= "5002";
taskService
.complete(taskId
);
System
.out
.println("任务执行完成");
}
@Test
public void findhistProcessInstance() {
List
<HistoricProcessInstance> list
= historyService
.createHistoricProcessInstanceQuery()
.processDefinitionKey(bpmnNameAndKey
)
.list();
if (!CollectionUtils
.isEmpty(list
)) {
for (HistoricProcessInstance historicProcessInstance
: list
) {
System
.out
.println("业务系统key\t" + historicProcessInstance
.getBusinessKey());
System
.out
.println("部署对象ID\t" + historicProcessInstance
.getDeploymentId());
System
.out
.println("执行时长\t" + historicProcessInstance
.getDurationInMillis());
System
.out
.println("流程定义ID\t" + historicProcessInstance
.getProcessDefinitionId());
System
.out
.println("流程定义的key\t" + historicProcessInstance
.getProcessDefinitionKey());
System
.out
.println("流程定义名称\t" + historicProcessInstance
.getProcessDefinitionName());
}
}
}
@Test
public void findHisTask(){
List
<HistoricTaskInstance> list
= historyService
.createHistoricTaskInstanceQuery()
.list();
if (!CollectionUtils
.isEmpty(list
)) {
for (HistoricTaskInstance historicTaskInstance
: list
) {
System
.out
.println("任务执行人\t" + historicTaskInstance
.getAssignee());
System
.out
.println("任务名称\t" + historicTaskInstance
.getName());
System
.out
.println("任务ID\t" + historicTaskInstance
.getId());
System
.out
.println("流程实例ID\t" + historicTaskInstance
.getProcessInstanceId());
System
.out
.println("*****************");
}
}
}
}