2

在使用 Eclipse (Kepler) 时,我一直无法将“jBPM 集成到 Web 应用程序中”。作为测试,我只是尝试将 jBPM 完整安装程序的评估示例中的代码复制到由 Maven JavaEE6 Archetype 生成的模板代码中。我已经在下面记录了我的步骤,以便可以轻松地重现问题。

1)添加到JBoss Standalone.xml:

<datasource jndi-name="java:jboss/jdbc/jbpm-ds" pool-name="jBPMDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
    <driver>h2</driver>
    <security>
        <user-name>sa</user-name>
        <password>sa</password>
    </security>
</datasource>

2) JBoss Central > Maven Project > filter on "javaee6"(创建“myservlet”项目): Archetype = jboss-javaee6-webapp 接受所有默认值

3) 设置 src\main\resources\META-INF\persistencet.xml 包含:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="primary">
      <!-- If you are running in a production environment, add a managed 
         data source, the example data source is just for proofs of concept! -->
      <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
      <properties>
         <!-- Properties for Hibernate -->
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
         <property name="hibernate.show_sql" value="false" />
      </properties>
   </persistence-unit>
</persistence>

4) 通过从 jBPM Full Installer 指向 \runtime 文件夹来添加一个 jBPM Runtime。

5) 选择jBPM Perspective,右键单击myservlet Project > Convert to jBPM Project。

6) 将 Java 构建路径条目添加到部署程序集 | jBPM 库。

7) 在 src\main\java\com\mycompany\mywebapp\controller 添加到(任意选择)MemberRegistration.java(作为项目的一部分自动创建)中来自评估示例代码的以下内容:

import java.util.HashMap;
import java.util.Map;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler;

8) 在同一模块中,在 register() 中添加以下内容,该内容也来自评估示例代码:

 try {
    // load up the knowledge base
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    HornetQHTWorkItemHandler humanTaskHandler = new HornetQHTWorkItemHandler(ksession);
    humanTaskHandler.setIpAddress("127.0.0.1");
    humanTaskHandler.setPort(5153);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);
    KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "krisv");
    params.put("reason", "Yearly performance evaluation");
    ksession.startProcess("com.sample.evaluation", params);
    System.out.println("Process started ...");
    logger.close();
    } catch (Throwable t) {
    t.printStackTrace();
}

在与六个 jBPM WAR 一起部署时,我们得到错误: 原因:java.lang.IllegalArgumentException:JBAS011470:未指定持久性单元名称,并且在应用程序部署“myservlet.war”中有 2 个持久性单元定义。要么将应用程序更改为只有一个持久性单元定义,要么为对持久性单元的每个引用指定 unitName。

有人可以解释这个错误的含义以及如何消除它吗?

谢谢你。铝

4

0 回答 0