Activiti environment configuration, project setup, integration with spring, simple example

Source: Internet
Author: User
Tags bind md5 xmlns log4j
 concept

WFMS (Workflow management System): Http://baike.baidu.com/view/977667.htm

WFMC (Workflow Management Alliance): http://baike.baidu.com/view/2497858.htm

Sample Project Download

Http://pan.baidu.com/s/1gd3iNfH

Environment Construction:

FBI WARNING Two video, screen recording expert recording, non-virus, the site is willing to take responsibility, download the documents please check MD5 first.

1.Eclipse configuring Tomcat and deploying the Web App. exe (md5:81c1dfb994ff5b2094ce0dac244da598)

Http://pan.baidu.com/s/1kTgb8PL

2.Activiti project Build and Spring integrated configuration. EXE (MD5:3DEBEEC0A00DC061C782CA0CDCC97F7D)

Http://pan.baidu.com/s/1sjyKCY5

Project Construction:

Maven Project Pom

    <!--jar Version Management-<properties> <springframework>4.0.2.RELEASE</springframework>

         


integration with spring:

Activiti.cfg.xml

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instan Ce "xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd "> <!--activiti processing engine configuration, to spring management--<bean id=" processengineconfiguration "class=" Org.activiti.spring.SpringProcessEngineConfiguration > <!--Configure the data source, and the system uses the same data source-<prope

          Rty name= "DataSource" ref= "DataSource"/> <property name= "Databaseschemaupdate" value= "true"/>  <property name= "Jobexecutoractivate" value= "false"/> <!--Unified transaction Management-<property Name= "TransactionManager" ref= "TransactionManager"/> <property name= "Activityfontname" value= "Song Body"/&gt

          ; <property name= "Labelfontname" value= "song Body"/> </bean> <bean id= "Processengine" class= "org.activiti.sp Ring. ProcessengineFactorybean "> <property name=" processengineconfiguration "ref=" processengineconfiguration "/> </bean > </beans>

Activiti API, the final interface is Processengine, get to processengine instance, get all the APIs in the Activiti system. The important interfaces are as follows:

Processengine processengine = Processengines.getdefaultprocessengine ();

 

Runtimeservice Runtimeservice = Processengine.getruntimeservice ();

Repositoryservice Repositoryservice = Processengine.getrepositoryservice ();

Taskservice Taskservice = Processengine.gettaskservice ();

Managementservice Managementservice = Processengine.getmanagementservice ();

Identityservice Identityservice = Processengine.getidentityservice ();

Historyservice Historyservice = Processengine.gethistoryservice ();

Formservice Formservice = Processengine.getformservice ();

The Activiti service framework is as follows

Activiticontroller Code

Package Org.xdemo.example.activiti.controller;

Import Java.awt.image.BufferedImage;

Import java.io.IOException;

Import Java.io.InputStream;

Import Java.util.HashMap;

Import java.util.List;

 

Import Java.util.Map;

Import Javax.annotation.Resource;

Import Javax.imageio.ImageIO;

 

Import Javax.servlet.http.HttpServletResponse;

Import Org.activiti.engine.ProcessEngine;

Import Org.activiti.engine.RepositoryService;

Import Org.activiti.engine.RuntimeService;

Import Org.activiti.engine.TaskService;

Import ORG.ACTIVITI.ENGINE.IMPL.CMD.GETDEPLOYMENTPROCESSDIAGRAMCMD;

Import Org.activiti.engine.impl.interceptor.Command;

Import org.activiti.engine.repository.ProcessDefinition;

Import org.activiti.engine.runtime.ProcessInstance;

Import Org.activiti.engine.task.Task;

Import Org.springframework.stereotype.Controller;

Import org.springframework.web.bind.annotation.RequestMapping;

Import Org.springframework.web.bind.annotation.RequestMethod; Import org.springframework.web.seRvlet.

 

Modelandview;

 

    @Controller @RequestMapping ("/process") public class Activiticontroller {@Resource processengine engine; /** * List all process templates */@RequestMapping (method = requestmethod.get) public Modelandview list (Modela

        Ndview Mav) {mav.addobject ("list", Util.list ());

        Mav.setviewname ("Process/template");

    return MAV; /** * Deployment Process */@RequestMapping ("deploy") public Modelandview Deploy (String processName, Mod

 

        Elandview Mav) {Repositoryservice service = Engine.getrepositoryservice (); if (null! = ProcessName) service.createdeployment (). Addclasspathresource ("diagrams/" +

 

        processName). deploy ();

 

        list<processdefinition> list = Service.createprocessdefinitionquery (). List ();

        Mav.addobject ("list", list);

        Mav.setviewname ("process/deployed");

    return MAV;

 

 }   /** * List of deployed processes */@RequestMapping ("deployed") public Modelandview deployed (Modelandview Mav) {

 

        Repositoryservice service = Engine.getrepositoryservice ();

 

        list<processdefinition> list = Service.createprocessdefinitionquery (). List ();

        Mav.addobject ("list", list);

 

        Mav.setviewname ("process/deployed");

    return MAV; }/** * Start a process instance */@SuppressWarnings ("Unchecked") @RequestMapping ("Start") public Mode

 

        Landview Start (String ID, Modelandview mav) {Runtimeservice service = Engine.getruntimeservice ();

 

        Service.startprocessinstancebyid (ID);

 

        list<processinstance> list = Service.createprocessinstancequery (). List ();

        Mav.addobject ("list", list);

 

        Mav.setviewname ("process/started");

    return MAV; /** * * All started process instances */@RequestMapping ("started")

    Public Modelandview started (Modelandview mav) {Runtimeservice service = Engine.getruntimeservice ();

 

        list<processinstance> list = Service.createprocessinstancequery (). List ();

        Mav.addobject ("list", list);

 

        Mav.setviewname ("process/started");

    return MAV;

        }/** * into the Task List */@RequestMapping ("task") public Modelandview Task (Modelandview mav) {

        Taskservice Service=engine.gettaskservice ();

        List<task> list=service.createtaskquery (). List ();

        Mav.addobject ("list", list);

        Mav.setviewname ("Process/task");

    return MAV; }/** * Completes the current node/@RequestMapping ("complete") public Modelandview completed (Modelandview

         

        Mav,string ID) {taskservice service=engine.gettaskservice ();

         

        Service.complete (ID);

  return new Modelandview ("Redirect:task");  }/** * All started process instances * * @throws IOException */@RequestMapping ("graphics") publ  IC void Graphics (string Definitionid, String instanceId, String taskId, Modelandview Mav, HttpServletResponse

        Response) throws IOException {Response.setcontenttype ("image/png");

 

        command<inputstream> cmd = null;

        if (Definitionid! = null) {cmd = new getdeploymentprocessdiagramcmd (Definitionid);

        } if (instanceId! = null) {cmd = new processinstancediagramcmd (instanceId); if (taskId! = null) {Task task = Engine.gettaskservice (). Createtaskquery (). TaskId (taskId). Sing

            Leresult ();

        cmd = new Processinstancediagramcmd (Task.getprocessinstanceid ());

            } if (cmd! = null) {InputStream is = Engine.getmanagementservice (). ExecuteCommand (CMD); int LEn = 0;

            Byte[] B = new byte[1024];

            while (len = is.read (b, 0, 1024x768))! =-1) {Response.getoutputstream (). Write (b, 0, Len); }

        }

    }

}

Example:


< reprint please indicate source: http://www.xdemo.org/spring-activiti-integration/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.