我正在尝试使我的 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 未绑定在此上下文中