activiti 配置(一)续

1.  activiti相关表23个,见附件


2.  创建配置文件activiti-content.xml

<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                           http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


  <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/hxzq1?useUnicode=true&characterEncoding=UTF-8" />
    <property name="username" value="root" />
    <property name="password" value="123456" />
  </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="mailServerHost" value="localhost" />
    <property name="mailServerPort" value="5025" />
    <property name="jpaHandleTransaction" value="true" />
    <property name="jpaCloseEntityManager" 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="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" />


</beans>


3. 创建流程

activiti 配置(一)续_第1张图片

activiti 配置(一)续_第2张图片
activiti 配置(一)续_第3张图片



4. 创建测试类


import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class HelloWord {

	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取默认流程引擎

	/**
	 * 部署流程定义
	 */
	@Test
	public void deploymentProcessDefintion() {
		Deployment deployment = processEngine.getRepositoryService() // 与流程定义和部署对象相关的service
				.createDeployment().name("activiti程序") // 创建部署对象
				.addClasspathResource("diagrams/MyProcess.bpmn") // 加载资源文件
				.addClasspathResource("diagrams/MyProcess.png").deploy();// 完成部署
		System.out.println("部署ID:" + deployment.getId());
		System.out.println("部署名称:" + deployment.getName());
	}

	/**
	 * 启动流程实例
	 */
	@Test
	public void startProcessInstance() {
		String processDefinitionKey = "myProcess";
		ProcessInstance pi = processEngine.getRuntimeService()
				.startProcessInstanceByKey(processDefinitionKey); // 使用流程定义Key启动流程实例,key对应MyProcess.bpmn中的ID
		System.out.println("流程实例ID:" + pi.getId());
		System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
	}

	/**
	 * 查询当前人的任务 <br>
	 * 表:act_ru_task
	 */
	@Test
	public void findPersonalTask() {
		String assignee = "张三";
		List<Task> list = processEngine.getTaskService().createTaskQuery()
				.taskAssignee(assignee).list();
		if (list != null && list.size() > 0) {
			for (Task t : list) {
				System.out.println("任务ID:" + t.getId());
				System.out.println("任务名称:" + t.getName());
				System.out.println("流程定义ID:" + t.getProcessDefinitionId());
				System.out.println("流程实例ID:" + t.getProcessInstanceId());
				System.out.println("执行对象ID:" + t.getExecutionId());
				System.out.println("任务执行人:" + t.getAssignee());
				System.out.println("任务执行时间:" + t.getCreateTime());
			}
		}
	}

	/**
	 * 完成任务
	 */
	@Test
	public void completePersonalTask() {
		String taskId = "908";
		processEngine.getTaskService().complete(taskId);

	}

}


你可能感兴趣的:(activiti 配置(一)续)