3

我正在尝试使我的 jBPM 项目持久化。因此我使用了本教程。起初我导入了所有需要的额外罐子(根据网站)。我还添加了mysql-connector-java-5.1.20-bin.jar因为我想使用 mysql 作为持久存储。

之后,我将“有状态”代码添加到我的项目中:

KnowledgeBase kbase = readKnowledgeBase(name);
StatefulKnowledgeSession ksession = null;
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
if(ProcessManager.sessionId == -1){
    ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
    ProcessManager.sessionId = ksession.getId();
}
else {
ksession = JBPMHelper.loadStatefulKnowledgeSession(
    kbase,
    ProcessManager.sessionId);
}

然后我添加到resources/META-INF文件中jBPM.properties

persistence.datasource.name=jdbc/jbpm-ds

persistence.datasource.user=test

persistence.datasource.password=测试

persistence.datasource.url=jdbc:mysql://localhost:3306/helpme

persistence.datasource.driverClassName=com.mysql.jdbc.Driver

持久性.启用=真

persistence.persistenceunit.name=org.jbpm.persistence.jpa

persistence.persistenceunit.dialect=org.hibernate.dialect.MySQLDialect

如果我现在运行该项目,总是会出现以下异常(on ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);):

javax.persistence.PersistenceException:[PersistenceUnit:org.jbpm.persistence.jpa] 无法构建 EntityManagerFactory

引起:org.hibernate.HibernateException:找不到数据源

原因:javax.naming.NameNotFoundException:名称 jdbc 未绑定在此上下文中

4

1 回答 1

1

我为我的问题找到了解决方案。通常JBPMHelper直接从jar加载 jBPM :

public static Properties getProperties() {
    Properties properties = new Properties();
    try {
        properties
            .load(JBPMHelper.class.getResourceAsStream("/jBPM.properties"));
    } catch (Throwable t) {
    // do nothing, use defaults
    }

    return properties;
}

我更换了加载机制,现在它正在jBPM.properties正确加载:

public static Properties getProperties() {
    Properties properties = new Properties();
    try {
        InputStream input
            = new FileInputStream("./resources/META-INF/jBPM.properties");
        properties.load(input);
        System.out.println("RPOP"+properties.toString());
    } catch (Throwable t) {
    // do nothing, use defaults
    }

    return properties;
}

(我的回答改编自 BartoszKP - 谢谢)

于 2013-10-08T19:19:06.043 回答