整合jBPM4.4+ssh过程(spring接管struts2和hibernate,例中都整合在application.xml中,没有单独的jbpm.hibernate.cfg.xml):
1.在sessionFactory的mappingLocations属性加入以下几个jbpm.*.hbm.xml由jBPM自带
classpath:jbpm.repository.hbm.xml classpath:jbpm.execution.hbm.xml classpath:jbpm.history.hbm.xml classpath:jbpm.task.hbm.xml classpath:jbpm.identity.hbm.xml
2.jBPM自己内部的配置(spring来接管processEngine)
这样子就配好啦。只要在要用的地方注入processEngine就可以了!简单吧
3.当然为了编程的方便,可以自己写个工具类,直接就可以通过注入这个类来获取所需要的jBPM服务
package com.ht.util; import java.util.List; import java.util.Map; import java.util.zip.ZipInputStream; import org.jbpm.api.ExecutionService; import org.jbpm.api.HistoryService; import org.jbpm.api.ManagementService; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import org.jbpm.api.RepositoryService; import org.jbpm.api.TaskService; import org.jbpm.api.task.Task; /** * jBPM4.4工具类 * * @author ht * */ public class JBPMUtil { private ProcessEngine processEngine; private RepositoryService repositoryService = null; private ExecutionService executionService = null; private TaskService taskService = null; private HistoryService historyService = null; private ManagementService managementService = null; public JBPMUtil(){ } public JBPMUtil(ProcessEngine processEngine) { this.processEngine = processEngine; repositoryService = processEngine.getRepositoryService(); executionService = processEngine.getExecutionService(); taskService = processEngine.getTaskService(); historyService = processEngine.getHistoryService(); managementService = processEngine.getManagementService(); } public ProcessEngine getProcessEngine() { return processEngine; } public void setProcessEngine(ProcessEngine processEngine) { this.processEngine = processEngine; System.out.println("processEngine="+processEngine); repositoryService = processEngine.getRepositoryService(); executionService = processEngine.getExecutionService(); taskService = processEngine.getTaskService(); historyService = processEngine.getHistoryService(); managementService = processEngine.getManagementService(); } public RepositoryService getRepositoryService() { return repositoryService; } public void setRepositoryService(RepositoryService repositoryService) { this.repositoryService = repositoryService; } public ExecutionService getExecutionService() { return executionService; } public void setExecutionService(ExecutionService executionService) { this.executionService = executionService; } public TaskService getTaskService() { return taskService; } public void setTaskService(TaskService taskService) { this.taskService = taskService; } public HistoryService getHistoryService() { return historyService; } public void setHistoryService(HistoryService historyService) { this.historyService = historyService; } public ManagementService getManagementService() { return managementService; } public void setManagementService(ManagementService managementService) { this.managementService = managementService; } /** * 部署新流程定义 * @param resourceName * @return 返回流程定义id */ public String deployNew(String resourceName) { return repositoryService.createDeployment().addResourceFromClasspath( resourceName).deploy(); } /** * 部署新流程定义(zip) * @param resourceName * @return 返回流程定义id */ public String deployZipNew(String resourceZipName){ ZipInputStream zis = new ZipInputStream(this.getClass().getResourceAsStream(resourceZipName)); return repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy(); } /** * 开始一个流程实例 * @param id * @param map * @return */ public ProcessInstance startPIById(String id,Mapmap){ return executionService.startProcessInstanceById(id, map); } /** * 完成任务 * @param taskId * @param map */ public void completeTask(String taskId,Map map){ taskService.completeTask(taskId, map); } /** * 完成任务 * @param taskId */ public void completeTask(String taskId){ taskService.completeTask(taskId); } /** * 将任务流转到指定名字的流程outcome中去 * @param taskId * @param outcome */ public void completeTask(String taskId,String outcome){ taskService.completeTask(taskId, outcome); } /** * 获得所有发布了的流程 * @return */ public List getAllPdList(){ return repositoryService.createProcessDefinitionQuery().list(); } /** * 获得所有流程实例 * @return */ public List getAllPiList(){ return executionService.createProcessInstanceQuery().list(); } /** * 根据流程实例Id,即executionId获取指定的变量值 * @param executionId * @param variableName * @return */ public Object getVariableByexecutionId(String executionId,String variableName){ return executionService.getVariable(executionId, variableName); } /** * 根据任务id,即taskId获取指定变量值 * @param taskId * @param variableName * @return */ public Object getVariableByTaskId(String taskId,String variableName){ return taskService.getVariable(taskId, variableName); } /** * 获取指定用户名字的任务 * @param userName * @return */ public List findPersonalTasks(String userName){ return taskService.findPersonalTasks(userName); } /** * 根据任务id获取任务 * @param taskId * @return */ public Task getTask(String taskId) { return taskService.getTask(taskId); } /** * 级联删除流程定义,直接删除该流程定义下的所有实例 * * @param deploymentId 流程定义id */ public void deleteDeploymentCascade(String deploymentId) { repositoryService.deleteDeploymentCascade(deploymentId); } }
完整的application.xml:
net.sourceforge.jtds.jdbc.Driver jdbc:jtds:sqlserver://localhost:1433;DatabaseName=jBPM sa 123 org.hibernate.dialect.SQLServerDialect true update
classpath*:com/ht/entity/*.hbm.xml classpath:jbpm.repository.hbm.xml classpath:jbpm.execution.hbm.xml classpath:jbpm.history.hbm.xml classpath:jbpm.task.hbm.xml classpath:jbpm.identity.hbm.xml
本文转自:http://hellotommy.iteye.com/blog/804233