`

第一个Activiti5.13 + Spring3.x例子

 
阅读更多
参考: http://www.iteye.com/topic/1130389

database不能使用
    <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://192.168.0.196:3306/activiti_demo" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>

否在很慢应该使用
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://192.168.0.196:3306/activiti_demo" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>


自动部署的配置:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">  
  ...  
  <property name="deploymentResources" value="classpath*:/org/activiti/spring/test/autodeployment/autodeploy.*.bpmn20.xml" />  
</bean>


pom.xml
<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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.pandy</groupId>
    <artifactId>activiti_demo</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>activiti_demo</name>
    <url>http://maven.apache.org</url>

    <properties>
        <spring.version>3.1.2.RELEASE</spring.version>
        <activiti.version>5.13</activiti.version>
        <spring-data-jpa.version>1.3.4.RELEASE</spring-data-jpa.version>
        <commons-dbcp.version>1.4</commons-dbcp.version>
        <commons-io.version>2.4</commons-io.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Activiti -->
        <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>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-data-jpa.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit-dep</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- WEB begin -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <!-- dbcp connection pool -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>${commons-dbcp.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>

    </dependencies>


    <repositories>
        <repository>
            <id>Alfresco Maven Repository</id>
            <url>https://maven.alfresco.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>


    <build>
        <finalName>activiti_demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.3.v20120416</version>
                <configuration>
                    <webApp>
                        <contextPath>/activiti_demo</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
    <display-name>activiti5.9web</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:/applicationContext.xml
        </param-value>
    </context-param>
    <!--Spring的ApplicationContext 载入 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Spring MVC Servlet -->
    <servlet>
        <servlet-name>springServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>



src/main/resources/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd">
    <context:component-scan base-package="com">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://192.168.0.196:3306/activiti_demo" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jobExecutorActivate" value="false" />
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
    <bean id="formService" factory-bean="processEngine" factory-method="getFormService"/>
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
    <!-- Activiti end -->
</beans>





src/main/webapp/WEB-INF/spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- 自动扫描且只扫描@Controller -->
    <context:component-scan base-package="com" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <mvc:annotation-driven />

    <mvc:default-servlet-handler />

    <!-- 定义JSP -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>


src/main/resources/MyProcess.bpmn
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task" activiti:assignee="test"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="110.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="310.0" y="200.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="710.0" y="240.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="127.0" y="125.0"></omgdi:waypoint>
        <omgdi:waypoint x="362.0" y="200.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="415.0" y="227.0"></omgdi:waypoint>
        <omgdi:waypoint x="727.0" y="227.0"></omgdi:waypoint>
        <omgdi:waypoint x="727.0" y="240.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>




TestController.java
package com;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
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 javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: pandy
 * Date: 13-9-16
 * Time: 上午9:36
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/a")
public class TestController {
    @Resource(name = "taskService")
    private TaskService taskService;

    @Resource(name = "runtimeService")
    private RuntimeService runtimeService;

    @Resource(name = "repositoryService")
    private RepositoryService repositoryService;

    @RequestMapping("/t")
    public String mytest() {
        System.out.println("开始执行工作流的方法");
        Date d1=new Date();

        //发布
        System.out.println("发布");
        repositoryService.createDeployment()
                .addClasspathResource("MyProcess.bpmn")
                .deploy();
        time(d1);

        Map<String, Object> variables = new HashMap<String, Object>();
       /* variables.put("employeeName", "Kermit");
        variables.put("numberOfDays", new Integer(4));
        variables.put("vacationMotivation", "I'm really tired!");*/


        //启动
        System.out.println("启动");
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess", variables);
        time(d1);

        //遍历任务
        System.out.println("遍历所有");
        //List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
        //List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("test").list();
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            System.out.println("#Task available: " + task.getId() + ":" + task.getName());


            Map<String, Object> taskVariables = new HashMap<String, Object>();
            taskService.complete(task.getId(), taskVariables);
            System.out.println("complete#Task: " + task.getId() + ":" + task.getName());
        }
        time(d1);

        //查看任务
        System.out.println("遍历所有");
        tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            System.out.println("@Task available: " + task.getId() + ":" + task.getName());
        }
        time(d1);
        return "index";
    }

    private void time(Date d1){
        Date d2 = new Date();
        long l = d2.getTime()-d1.getTime();
        System.out.println(l/1000);

    }

}



http://localhost:8080/activiti_demo/a/t
开始执行工作流的方法
发布
4
启动
9
遍历所有
#Task available: 926:User Task
complete#Task: 926:User Task
18
遍历所有
22


问题:为什么耗时那么多?待解决。
分享到:
评论

相关推荐

    activiti-spring-5.13.jar

    activiti-spring-5.13.jar

    activiti源码+用户手册.zip

    1. **快速入门**:介绍如何安装和配置Activiti,以及如何启动第一个流程实例。 2. **BPMN 2.0 知识**:BPMN(Business Process Model and Notation)是一种标准化的语言,用于描述业务流程。手册会解释各种图形元素...

    activiti 5.13 的依赖jar包

    Activiti 是一个开源的工作流和业务流程管理(BPM)引擎,它被广泛用于企业级应用中,以实现流程自动化。版本5.13是该引擎的一个特定版本,包含了对某些功能的改进和修复。本篇文章将深入探讨Activiti 5.13中的关键...

    Maven整合Spring3.X+Mybatis3.X

    NULL 博文链接:https://whatisjavabean.iteye.com/blog/2017035

    activiti+spring+srping Mvc+mybatis+maven整合

    本项目是关于"activiti+spring+spring Mvc+mybatis+maven"的整合,旨在创建一个基于Activiti工作流引擎、Spring、Spring MVC、MyBatis以及Maven的开发环境。下面将详细介绍这些技术及其整合过程。 首先,`activiti`...

    Activiti5.13帮助文档.CHM

    Activiti5.13帮助文档.CHM

    activiti5.13设计器eclipse插件

    Activiti 5.13 版本是该引擎的一个重要迭代,它提供了丰富的功能和改进,使得开发者能够更有效地设计、实现和管理业务流程。 Eclipse 插件是集成开发环境(IDE)的一种扩展,它可以增强 Eclipse 的功能,使其更...

    activiti-5.13.zip

    Activiti 是一个开源的工作流和业务流程管理(BPM)平台,它基于Java技术栈,设计用于企业级应用。在“activiti-5.13.zip”这个压缩包中,我们能够获取到Activiti 5.13版本的相关资源,包括核心引擎、用户界面以及...

    activiti-5.13.

    Activiti 是一个开源的工作流和业务流程管理(BPM)平台,它被广泛用于构建企业级的应用程序。在"activiti-5.13."这个版本中,我们聚焦于 Activiti 的核心特性和使用环境。 首先,理解 BPM(Business Process ...

    Activiti 5.13 用户指南(中文版)

    Activiti 5.13是该平台的一个版本,提供了相对成熟和完整的流程设计、执行、管理和分析功能。Activiti用户指南是帮助用户了解和使用Activiti产品的官方文档。下面将基于文档的部分内容,介绍与Activiti 5.13相关的...

    activiti eclipse+idea插件.rar

    activiti 工作流idea+eclipse 需要的插件 idea 用actiBpm导入 eclipse 安装前需从文件夹中复制4个jar包

    activiti-spring-5.7.jar.zip

    首先,`activiti-spring-5.7.jar`是Activiti与Spring框架的一个特定版本的集成库,它包含了Activiti流程引擎和Spring框架的适配器,使得Activiti可以在Spring环境中无缝运行。5.7版本是Activiti的一个稳定版本,提供...

    Activiti7完整jar包.rar

    Activiti 是一个开源的工作流程和业务自动化引擎,广泛应用于企业级应用中,提供流程定义、执行、监控等全套解决方案。这个“Activiti7完整jar包.rar”包含了 Activiti v7.1.0.M6 版本的一系列核心组件,便于在项目...

    springboot2+vue2+activiti7+myflow工作流设计demo

    springboot2+vue2+activiti7+myflow(vue下public目录下 window.open打开)工作流设计请假实战例子。。

    基于 springboot+mybatis_+shiro + redis+activiti+quarts+quart.zip

    这个项目似乎是一个使用Spring Boot、MyBatis、Shiro、Redis、Activiti、Quartz和Quartz库的综合系统。以下是这些技术的详细说明: **1. Spring Boot** Spring Boot是Spring框架的一个扩展,旨在简化Java Web应用的...

    activiti-5.21 + Activiti5.20.0整合spring4.15示例

    1. **配置 Spring**:首先,你需要创建一个 Spring 配置文件(如 `applicationContext.xml`),并引入 Activiti 的核心库和 Spring 的 Activiti 支持。配置数据源、事务管理器以及 Activiti 的工厂bean,例如 `...

    activiti5.13开发所需JAR包

    Activiti 是一个开源的工作流和业务自动化引擎,广泛应用于企业级应用中,提供流程定义、执行、监控和分析等功能。版本5.13是该引擎的一个稳定版本,它支持多种集成框架,如SpringMVC、MyBatis和Hibernate,使得在...

    springboot2.x 集成activiti5.22+ modeler可视化界面

    SpringBoot 2.x 集成 Activiti 5.22 和 Modeler 可视化界面是一项常见的企业级应用开发任务,它涉及到流程自动化、微服务架构以及UI设计等多个技术领域。下面将详细介绍这个集成过程中的关键知识点。 首先,**...

    activiti7.X达梦支持.zip

    总结起来,这个压缩包提供了一个经过修改的Activiti 7.x版本,它不仅支持达梦数据库,还兼容了JDK 11,这对那些希望在使用达梦数据库的环境中运行Activiti的企业来说是个好消息。同时,结合Spring和Java的特性,...

    activiti-Engine API 5.13.zip

    Activiti 是一个开源的工作流程引擎,它为业务流程自动化提供了强大的支持。在本文中,我们将深入探讨Activiti Engine API 5.13版本的核心概念、功能以及如何利用它来实现高效的工作流管理。 首先,我们要了解什么...

Global site tag (gtag.js) - Google Analytics