springbootactiviti⼯作流简单⽰例
最近⼀直研究springboot,根据⼯作需求,⼯作流需要作为⼀个单独的微服务⼯程来提供给其他服务调⽤,现在简单的写下⼯作流(使⽤的activiti)微服务的搭建与简单使⽤
jdk:1.8
数据库:mysql  5.7
IDE:eclipse
springboot:1.5.8
activiti:6.0.0
1.新建空⽩的maven微服务架构
新建maven项⽬的流程不在阐述,这⾥添加上activiti、myslq连接的依赖,只贴主要代码
1.
2. <modelVersion>4.0.0</modelVersion>
3. <groupId&</groupId>
4. <artifactId>xxx</artifactId>
5. <version>0.0.1-SNAPSHOT</version>
6. <properties>
7. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
8. <java.version>1.8</java.version>
9. </properties>
10.
1. <parent>
2. <groupId>org.springframework.boot</groupId>
3. <artifactId>spring-boot-starter-parent</artifactId>
4. <version>1.
5.8.RELEASE</version>
5. </parent>
6. <dependencies>
7. <dependency>
8. <groupId>org.springframework.boot</groupId>
9. <artifactId>spring-boot-starter-web</artifactId>
0. </dependency>
1. <dependency>
2. <groupId>org.activiti</groupId>
3. <artifactId>activiti-spring-boot-starter-basic</artifactId>
4. <version>6.0.0</version>
5. </dependency>
6. <dependency>
7. <groupId>org.springframework.boot</groupId>
8. <artifactId>spring-boot-starter-data-jpa</artifactId>
9. </dependency>
0. <dependency>
1. <groupId>org.springframework.boot</groupId>
2. <artifactId>spring-boot-starter-thymeleaf</artifactId>
3. </dependency>
4. <dependency>
5. <groupId>org.springframework.boot</groupId>
6. <artifactId>spring-boot-starter-web</artifactId>
7. </dependency>
38.
9. <dependency>
0. <groupId>mysql</groupId>
1. <artifactId>mysql-connector-java</artifactId>
2. <scope>runtime</scope>
3. </dependency>
4. <dependency>
5. <groupId>org.springframework.boot</groupId>
6. <artifactId>spring-boot-starter-tomcat</artifactId>
7. </dependency>
8. <dependency>
9. <groupId>org.springframework.boot</groupId>
0. <artifactId>spring-boot-starter-test</artifactId>
1. <scope>test</scope>
2. </dependency>
3. </dependencies>
4. <build>
5. <plugins>
6. <plugin>
7. <groupId>org.springframework.boot</groupId>
8. <artifactId>spring-boot-maven-plugin</artifactId>
9. </plugin>
0. </plugins>
1. </build>
2. </project>
确认服务是可⽤
2.连接服务名、服务端⼝、数据库配置
在resources⽬录下的application.properties(项⽬定位原因没有使⽤yaml,可根据⾃⼰项⽬使⽤)
1. spring.datasource.sql.jdbc.Driver
2. spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activity?characterEncoding=utf8&useSSL=true
3. spring.datasource.username=root
4. spring.datasource.password=root
5. spring.jpa.properties.hibernate.hbm2ddl.auto=update
6. spring.jpa.show-sql=true
7. server.port=8081
8. t-path=/activity
9. server.session.timeout=10
0. at.uri-encoding=UTF-8
确认配置的数据库可⽤
3.main
1. import org.springframework.boot.SpringApplication;
2. import org.springframework.boot.autoconfigure.SpringBootApplication;
3.
4. /**
5. * Created by Guo on 2017/11/15.
6. */
7. @SpringBootApplication
8. public class ActivityApp
9. {
0. public static void main(String[] args)
1. {
2. SpringApplication.run(ActivityApp.class, args);
3. }
4. }
4.service及实现
service:
1. import ine.task.TaskQuery;
2. import org.springframework.web.bind.annotation.RequestMapping;
3. import org.springframework.web.bind.annotation.RequestMethod;
4. import org.springframework.web.bind.annotation.RestController;
5.
6. @RestController
7. @RequestMapping("/activityService")
8. public interface ActivityConsumerService {
9. /**
0. * 流程demo
1. * @return
2. */
3. @RequestMapping(value="/startActivityDemo",method=RequestMethod.GET)
4. public boolean startActivityDemo();
15.
6. }
impl
1. import java.util.HashMap;
2. import java.util.Map;
3.
4. import ine.RuntimeService;
5. import ine.TaskService;
6. import ine.ity.ExecutionEntity;
7. import ine.task.Task;
8. import ine.task.TaskQuery;
9. import org.apachemons.lang3.StringUtils;
0. import org.springframework.beans.factory.annotation.Autowired;
1. import org.springframework.stereotype.Service;
12.
3. import com.hongguaninfo.activity.service.ActivityConsumerService;
4. @Service("activityService")
5. public class ActivityConsumerServiceImpl implements ActivityConsumerService {
16.
7. @Autowired
8. private RuntimeService runtimeService;
9. @Autowired
0. private TaskService taskService;
21.
2. @Override
3. public boolean startActivityDemo() {
4. System.out.println("method ");
5. Map<String,Object> map = new HashMap<String,Object>();
6. map.put("apply","zhangsan");
7. map.put("approve","lisi");
8. //流程启动
9. ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);
0. String processId = Id();
1. String taskId = Tasks().get(0).getId();
2. taskServiceplete(taskId, map);//完成第⼀步申请
33.
4. Task task = ateTaskQuery().processInstanceId(processId).singleResult();
springboot架构图
5. String taskId2 = Id();
6. map.put("pass", false);
7. taskServiceplete(taskId2, map);//驳回申请
8. System.out.println("method ");
9. return false;
0. }
1. }
5.bpmn

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。