springboot鏁村悎activiti
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot鏁村悎activiti相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/man' title='man'>man stc ima codehaus ext report override context prefix
1.绗竴姝ユ坊鍔燽pmn鏂囦欢寰楁彃浠讹紝涓嶇劧娌℃硶鏌ョ湅鍜岀紪杈慴pmn鏂囦欢锛屾坊鍔犳彃浠剁殑鏂规硶鍚勮嚜鐧惧害鍗冲彲锛屽緢绠€鍗?/p>
2.瀹夎濂絙pmn鎻掍欢鍚庡紑濮嬫柊寤篵pmn鏂囦欢锛屼篃灏辨槸鐢绘祦绋嬪浘
涓€鑸槸鍦ㄤ唬鐮佷腑杩涜鎸囧畾娴佺▼瀹℃壒浜虹殑锛屾垜杩欓噷鍙仛鍏ラ棬妗堜緥
3.娣诲姞pom渚濊禆
杩欓噷鍖呭惈浜嗗湪绾胯璁℃祦绋嬪浘鐨勭浉鍏充緷璧栵紝鍦ㄤ笅涓€绡囦細鍐欏嚭鏉ワ紝椤圭洰涓竴鑸兘鏄湪鍓嶇鍦ㄧ嚎璁捐锛涙墍浠ョ洿鎺ユ斁涓婂幓涔熸病浜?/p>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com</groupId> <artifactId>springboot_activiti</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot_activiti</name> <description>Demo project for Spring Boot</description> <properties> <springboot.version>2.2.0.RELEASE</springboot.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <activiti.version>6.0.0</activiti.version> </properties> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${activiti.version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${activiti.version}</version> <exclusions> <exclusion> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <artifactId>spring-context</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-jdbc</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-tx</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-orm</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>mybatis</artifactId> <groupId>org.mybatis</groupId> </exclusion> <exclusion> <artifactId>activation</artifactId> <groupId>javax.activation</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>${activiti.version}</version> </dependency> <!-- Activiti 娴佺▼鍥?--> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-common-rest</artifactId> <version>${activiti.version}</version> </dependency> <!-- Activiti 鍦ㄧ嚎璁捐 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-modeler</artifactId> <version>5.22.0</version> <exclusions> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-context</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-tx</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-web</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-security-config</artifactId> <groupId>org.springframework.security</groupId> </exclusion> <exclusion> <artifactId>spring-security-core</artifactId> <groupId>org.springframework.security</groupId> </exclusion> <exclusion> <artifactId>spring-security-crypto</artifactId> <groupId>org.springframework.security</groupId> </exclusion> <exclusion> <artifactId>spring-security-web</artifactId> <groupId>org.springframework.security</groupId> </exclusion> <exclusion> <artifactId>spring-webmvc</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>activation</artifactId> <groupId>javax.activation</groupId> </exclusion> <exclusion> <artifactId>commons-io</artifactId> <groupId>commons-io</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>${springboot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>RELEASE</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8081</port> <path>/activity</path> <systemProperties> <com.sun.management.jmxremote.port>4000</com.sun.management.jmxremote.port> </systemProperties> </configuration> </plugin> </plugins> </build> </project>
4.yml鏂囦欢
杩欓噷閲囩敤鐨勬暟鎹簱杩樻槸mysql
杩欓噷鏈変釜闇€瑕佹敞鎰忕殑鍦版柟锛宻pringboot2.2涓殑driver-class-name鍊煎彉浜嗭紝涓嶆槸浠ュ墠鐨勯偅涓簡锛屼笉鐒朵細鎶ラ敊
spring: datasource: url: jdbc:mysql://localhost:3307/t2?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&serverTimezone=UTC username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver activiti: # 鑷姩閮ㄧ讲楠岃瘉璁剧疆:true-寮€鍚紙榛樿锛夈€?span style="color: #0000ff;">false-鍏抽棴 check-process-definitions: false #鑷姩閮ㄧ讲鏂囦欢璺緞鍚庣紑 # process-definition-location-prefix: classpath:/processes/ # process-definition-location-suffixes: # - **.bpmn # - **.bpmn20.xml server: port: 8082
5.閰嶇疆宸茬粡濂戒簡锛屼笅闈㈠紑濮嬪啓浠g爜浜嗭紝鍙槸鍒濇鍐欎簡涓€浜涙柊寤烘祦绋嬶紝姝e父鎻愪氦娴佺▼锛岀洿鎺ョ粨鏉熸祦绋嬶紝浠ュ強鏌ヨ寰呭姙鐨勬渚嬶紝缁嗚妭杩橀渶瑕佸悇鑷嚜宸卞幓璋冭瘯瀛︿範
controller
package com.springboot_activiti.controller; import com.springboot_activiti.service.ActivityConsumerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/activiti") public class ActivitiController { @Autowired private ActivityConsumerService activityConsumerService; /** * 娉ㄥ唽娴佺▼ * @return */ @RequestMapping("/createDeployment") public Boolean createDeployment(){ return activityConsumerService.createDeployment(); } /** * 鍚姩娴佺▼ * @return */ @RequestMapping("/startActivityDemo") public Boolean startActivityDemo(){ return activityConsumerService.startActivityDemo("test01"); } /** * 鑾峰彇寰呭姙 * @return */ @RequestMapping("/getTaskList") public boolean getTaskList(){ return activityConsumerService.getTaskList(); } /** * 鎻愪氦 * @param taskId * @return */ @RequestMapping("/complete") public boolean complete(String taskId){ return activityConsumerService.complete(taskId); } /** * 鏍规嵁娴佺▼id鐩存帴缁撴潫娴佺▼ * @paramru * @return */ @RequestMapping("/deleteProcessInstance") public boolean deleteProcessInstance(String runId){ return activityConsumerService.deleteProcessInstance(runId); } }
service
package com.springboot_activiti.service; public interface ActivityConsumerService { boolean createDeployment(); boolean startActivityDemo(String key); boolean getTaskList(); boolean complete(String taskId); boolean deleteProcessInstance(String runId); }
瀹炵幇绫?/p>
package com.springboot_activiti.service; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.repository.DeploymentBuilder; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("activityService") public class ActivityConsumerServiceImpl implements ActivityConsumerService { @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private RepositoryService repositoryService; /** * 娉ㄥ唽涓€涓祦绋? * @return */ @Override public boolean createDeployment() { DeploymentBuilder builder=repositoryService.createDeployment(); builder.addClasspathResource("test01.bpmn"); builder.deploy(); return true; } /** * 鏌ヨ寰呭姙 * @return */ public boolean getTaskList(){ //鑾峰彇寰呭姙鐨勪竴浜涗俊鎭紝杩欓噷鍙互浼犲叆闇€瑕佹煡璇㈢殑鐢ㄦ埛锛? //鎴戣繖閲屾煡璇㈢殑鎵€鏈夊緟鍔?/span> List<Task> tasks = taskService.createTaskQuery().list(); for (Task t:tasks) { System.out.println(t.getCreateTime()); System.out.println(t.getId()); System.out.println(t.getName()); System.out.println(t.getProcessInstanceId()); System.out.println(t.getTaskDefinitionKey()); System.out.println(t.getParentTaskId()); } return true; } /** * 鏍规嵁娴佺▼key寮€鍚竴涓祦绋? * @param key * @return */ @Override public boolean startActivityDemo(String key) { ProcessInstance test01 = runtimeService.startProcessInstanceByKey(key); String id = test01.getId(); System.out.println("娴佺▼id="+id); /* */ /* String assignee = "abc";*/ return true; } /** * 鏍规嵁浠诲姟id鎻愪氦浠诲姟 * @param taskId * @return */ @Override public boolean complete(String taskId){ taskService.complete(taskId); return true; } /** * 鏍规嵁娴佺▼id鐩存帴缁撴潫娴佺▼ * @param runId * @return */ @Override public boolean deleteProcessInstance(String runId){ runtimeService.deleteProcessInstance(runId,"缁撴潫"); return true; } }
鍚姩绫伙紝杩欓噷瀛樺湪涓€涓湪绾胯鍥捐璁$殑楠岃瘉澶勭悊锛?/p>
package com.springboot_activiti; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @ComponentScan("com") @SpringBootApplication @EnableAutoConfiguration(exclude = { org.activiti.spring.boot.SecurityAutoConfiguration.class }) public class SpringbootActivitiApplication { public static void main(String[] args) { SpringApplication.run(SpringbootActivitiApplication.class, args); } }
鎵€鏈夌殑浠g爜宸茬粡鍐欏ソ浜?/p>
澶囨敞璇存槑锛?/p>
椤圭洰鍚姩浼氭柊寤?8寮犺〃锛屽悇鑷唬琛ㄧ殑鍚箟鑷鐧惧害鎶?/p>
鍥犱负鎴戠殑鏁版嵁閮芥槸鐩存帴鍦ㄦ祦绋嬪浘bpmn鏂囦欢閲岄潰鍐欏ソ鐨勶紝瀹為檯涓偗瀹氭槸鍦ㄤ唬鐮侀噷闈㈡寚瀹氱殑
棣栧厛璁块棶娉ㄥ唽娴佺▼
鍚姩娴佺▼锛堜細杩斿洖涓€涓祦绋媔d锛?/p>
鏌ョ湅寰呭姙灏卞彲浠ヨ幏鍙栫浉鍏崇殑淇℃伅浜?/p>
姝e父鎻愪氦浠诲姟锛屼細瀹℃壒鍒颁笅涓€鑺傜偣锛堟煡鐪嬪緟鍔炲彲浠ュ緱鍒颁换鍔d锛?/p>
鐩存帴缁撴潫娴佺▼锛堥潪姝e父缁撴潫锛屽惎鍔ㄦ祦绋嬬殑id浼犲叆鍗冲彲锛?/p>
璇锋眰妗堜緥
鏌ヨ寰呭姙
鍚姩娴佺▼
以上是关于springboot鏁村悎activiti的主要内容,如果未能解决你的问题,请参考以下文章
銆愯浆銆?springboot鏁村悎redis-sentinel鏀寔Cache娉ㄨВ