如何在JBPM中为用户任务编写代码

时间:2016-03-21 14:24:54

标签: java drools jbpm

对于JBPM,我是新手。虽然我已经使用脚本任务和用户任务创建了示例应用程序。当我删除用户任务时,bpmn正在执行。但是,当我保留UserTask时,它会抛出异常。

以下是我的代码:

package com.Sservlet;

import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

import org.drools.KnowledgeBase;
import org.drools.SystemEventListenerFactory;
import org.drools.builder.*;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
import org.jbpm.process.workitem.wsht.CommandBasedWSHumanTaskHandler;
import org.jbpm.task.*;
import org.jbpm.task.service.*;

public class SServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("Jcr.bpmn2"), ResourceType.BPMN2);

        KnowledgeBase kbase = kbuilder.newKnowledgeBase();
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        CommandBasedWSHumanTaskHandler taskHandler = new CommandBasedWSHumanTaskHandler(ksession);

        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new ServiceTaskHandler());

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task");
        TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
        TaskServiceSession taskSession = taskService.createSession();

        // now register new users and groups
        List list = taskSession.getTasksAssignedAsPotentialOwner("John", "en-UK");
        taskHandler.connect();
        ProcessInstance processInstance = ksession.startProcess("TestHandle");

        System.out.println("hello here are");
    }
}

我收到No Persistence提供程序异常:

  

javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.task

我这里不需要任何数据库插入。这是一个简单的用户任务。有没有解决方案?

0 个答案:

没有答案