抛org.activiti.engine.ActivitiObjectNotFoundException: no deployed process definition found with id 'simpleApprovalProcess'错误

今天在学习activiti5的时候遇到了这个问题:org.activiti.engine.ActivitiObjectNotFoundException: no deployed process definition found with id 'simpleApprovalProcess',网上这方面的资料少,一直没有找到为什么会出现这个错误。最后通过调试程序,终于发现这个问题是自己粗心造成的。

今天在学习activiti5的时候遇到了这个问题:org.activiti.engine.ActivitiObjectNotFoundException: no deployed process definition found with id 'simpleApprovalProcess',网上这方面的资料少,一直没有找到为什么会出现这个错误。最后通过调试程序,终于发现这个问题是自己粗心造成的。

错误信息:

70 [main] INFO org.activiti.engine.ProcessEngines - Initializing process engine using configuration 'file:/F:/Project_All/Eclipase_Workspace/Activiti_test01/bin/activiti.cfg.xml'

89 [main] INFO org.activiti.engine.ProcessEngines - initializing process engine for resource file:/F:/Project_All/Eclipase_Workspace/Activiti_test01/bin/activiti.cfg.xml

2015-2-14 9:07:16 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from resource loaded through InputStream

17767 [main] INFO org.activiti.engine.impl.ProcessEngineImpl - ProcessEngine default created

17767 [main] INFO org.activiti.engine.impl.jobexecutor.JobExecutor - Starting up the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].

17818 [main] INFO org.activiti.engine.ProcessEngines - initialised process engine default

17819 [Thread-1] INFO org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable - JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs

18204 [main] INFO org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource bpmn/activiti_test01.bpmn20.xml

21012 [main] ERROR org.activiti.engine.impl.interceptor.CommandContext - Error while closing command context

org.activiti.engine.ActivitiObjectNotFoundException: no deployed process definition found with id 'simpleApprovalProcess'

at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:55)

at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:59)

at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:36)

at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)

at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)

at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)

at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)

at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)

at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:72)

at com.bug315.ActivitiTest01.main(ActivitiTest01.java:22)

Exception in thread "main" org.activiti.engine.ActivitiObjectNotFoundException: no deployed process definition found with id 'simpleApprovalProcess'

at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:55)

at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:59)

at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:36)

at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)

at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)

at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)

at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)

at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)

at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:72)

at com.bug315.ActivitiTest01.main(ActivitiTest01.java:22)

我的Java代码:

package com.bug315;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
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;

public class ActivitiTest01 {

	public static void main(String[] args) {
		// 创建流程引擎
		ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
		
		// 获取流程存储服务组件
		RepositoryService repositoryService = processEngine.getRepositoryService();
		
		// 获取运行时服务组件
		RuntimeService runtimeService = processEngine.getRuntimeService();
		
		// 获取流程任务组件
		TaskService taskService = processEngine.getTaskService();
		
		// 1、部署流程文件
		repositoryService.createDeployment().name("myProcess")
			.addClasspathResource("bpmn/activiti_test01.bpmn").deploy();
		
		// 2、启动流程
		ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess"); 
				//runtimeService.startProcessInstanceById("myProcess");
		System.out.println(processInstance.getId());
		
		// 3、查询第一个任务
		Task task = taskService.createTaskQuery().singleResult();
		System.out.println("============" + task.getId() + "============");
		taskService.complete(task.getId()); // 完成任务
		
		// 4、查询第二个任务
		task = taskService.createTaskQuery().singleResult();
		System.out.println("============" + task.getId() + "============");
		taskService.complete(task.getId()); // 完成任务
		
		// 5、流程结束
		task = taskService.createTaskQuery().singleResult();
		System.out.println("============ 任务结束(" + task + ") ============");
	}
	
}

解决办法:

仔细看上面的异常是指定的流程定义ID不存在。再仔细看看我的代码,我的愿意是通过流程定义中<process>元素的id去启动流程。但是我错误写使用了startProcessInstanceById方法。因此将startProcessInstanceById()方法改为startProcessInstanceByKey()方法就解决问题了。你到act_re_procdef表中去查看ID_字段的格式为:myProcess:1:4,所以根本就不存在ID等于myProcess的流程定义。这些都是初心大意造成的,不知你是否也犯过这种低级错误。

部分流程XML代码:

<process id="myProcess" name="My process" isExecutable="true">

部分测试代码:

// 2、启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess"); 
// runtimeService.startProcessInstanceById("myProcess"); // 这里调用方法写错了
天下之事常成于困约,而败于奢靡。——陆游
2 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号