Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Activiti Spring Integration

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain the example analysis of Activiti Spring integration for you in detail. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. Version

Activiti version: 5.17.0

Eclipse version: Kepler Service Release 2

JDK version: 1.7.0R51

Mysql version: 5.5.33

two。 Create an Activiti project

After integrating the Activiti Eclipse Designer plug-in in Eclipse (see "Eclipse Integrated Activiti Eclipse Designer plug-in")

File- > New- > Other- > Activiti- > Activiti Project

Project Name is activiti-demo

After you create a project, the default is like this

It is already a maven structure, but you still need to convert the project to a maven project

Right-click on the project-> Configure- > Conver to Maven Project, see the following figure

After the conversion is complete, edit the pom.xml and add the dependency package, as shown below

4.0.0 org.activiti.examples activiti-examples 1.0-SNAPSHOT jar BPMN 2.0 with Activiti-Examples 5.17.0 3.2.4.RELEASE 5.1.29 junit junit 4.11 org.springframework spring-context ${spring-version} org.springframework Spring-jdbc ${spring-version} org.springframework spring-tx ${spring-version} org.activiti activiti-engine ${activiti-version} org.activiti activiti-spring ${activiti-version} Mysql mysql-connector-java ${mysql-version} org.slf4j slf4j-api 1.7.2 org.slf4j slf4j-jdk14 1.7.2

The directory structure is as follows

At this point, the preparatory work is over.

3. Start the first integration of Demo3.1 spring and activiti

Add the configuration file of Spring under src/main/resources. The spring-activiti.xml is as follows

3.2Primary interface of Activiti

The main bean functions of each Activiti are as follows:

ProcessEngineConfiguration Activiti process engine

The main interface of processEngine Activiti

Resource operation interface of repositoryService Activiti

RuntimeService Runtime Operation Interface (mostly operating process examples)

TaskService task operation interface

IdentityService identity operation interface (users and user groups)

HistoryService history query interface

FormService form data binding Interface

ManagementService management interface

3.3Design Workflow DemoProcess

Create a workflow under src/main/resources/diagrams/, named DemoProcess.bpmn, as shown in the following figure, and create a new flowchart using the Activiti plug-in

Enter Activiti Diagram Editor at this time, click in the blank, and set id and name,id in the property bar below to be the key of the process, which is used later when starting the process.

In the figure, set the ID of the stand-alone FirstTask to firstTask, and set the ID of SecondTask to secondTask in the same way

Once set up, the workflow opens in xml like this

At this point, the process design is complete.

3.4.Create test class DemoProcess.javapackage com.lei.demo.activiti.spring.test;import java.util.List;import org.activiti.engine.HistoryService;import org.activiti.engine.ProcessEngine;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.repository.Deployment;import org.activiti.engine.runtime.ProcessInstance;import org.activiti.engine.task.Task;import org.springframework.context.ApplicationContext Import org.springframework.context.support.ClassPathXmlApplicationContext;public class DemoProcess {private static ApplicationContext context; public static void main (String [] args) {System.out.println ("start"); context = new ClassPathXmlApplicationContext ("spring-activiti.xml") / / create Activiti process engine, Activiti main interface ProcessEngine processEngine = (ProcessEngine) context.getBean ("processEngine"); System.out.println ("processEngine Name:" + processEngine.getName ()); / / get the resource operation interface of Activiti RepositoryService repositoryService = processEngine.getRepositoryService () / / get the runtime operation interface (most operation process instances) RuntimeService runtimeService = processEngine.getRuntimeService () / / deployment process definition. After deployment, activiti automatically creates tables based on database configuration. Add data Deployment deployment = repositoryService .createDeploxation () .addClasspathResource ("diagrams/DemoProcess.bpmn") .deploy () System.out.println ("deployment ID:" + deployment.getId () + "deployment Name:" + deployment.getName ()); / start the process instance. The startProcessInstanceByKey parameter DemoProcess is ID ProcessInstance instance = processEngine .getRuntimeService (). StartProcessInstanceByKey ("DemoProcess") in DemoProcess.bpmn; String procId = instance.getId (); System.out.println ("procId:" + procId) / / get the first task. The taskDefinitionKey parameter is ID TaskService taskService = processEngine.getTaskService () of the UserTask in the process; List tasks = taskService.createTaskQuery (). TaskDefinitionKey ("firstTask"). List (); for (Task task: tasks) {System.out.println ("Task Information: taskID -" + task.getId () + "taskName -" + task.getName () / / claim task taskService.claim (task.getId (), "testUser");} / / output the number of tasks System.out.println under testUser before completing the task ("number of task claimed by testUser before completing the task:" + taskService.createTaskQuery (). TaskAssignee ("testUser"). Count ()) / / check whether testUser can now get the task tasks = taskService.createTaskQuery (). TaskAssignee ("testUser") .list (); for (Task task: tasks) {System.out.println ("Task for testUser:" + task.getName ()); / / complete the task taskService.complete (task.getId ()) } / / after completing the task, output the number of tasks under testUser System.out.println ("number of task claimed by testUser after completing the task:" + taskService.createTaskQuery (). TaskAssignee ("testUser"). Count ()); / / get and claim the second task tasks = taskService.createTaskQuery (). TaskDefinitionKey ("secondTask") .list () For (Task task: tasks) {System.out.println ("Task Information: taskID -" + task.getId () + "taskName -" + task.getName ()); taskService.claim (task.getId (), "testUser") } / / complete the second task termination process for (Task task: tasks) {taskService.complete (task.getId ());} / / verify whether the process ends HistoryService historyService = processEngine.getHistoryService () HistoricProcessInstance historicProcessInstance = historyService .createHistorical ProcessInstanceQuery () .processInstanceId (procId) .singleResult () System.out.println ("process instance end time:" + historicProcessInstance.getEndTime ()); System.out.println ("end");}}

Screenshot of running result

This is the end of this article on "sample Analysis of Activiti Spring Integration". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report