根据
http://www.intelligrape.com/blog/2010/05/14/embedding-jbpm-4-3-in-a-grails-1-2-2-application/
http://hi.baidu.com/xionglian1123/blog/item/95d7c719de1f0adbac6e75a1.html
进行整合
1 首先现在JBPM4.3
<process name="helloWorld" xmlns="http://jbpm.org/4.0/jpdl"> <start> <transition to="printHelloWorld"/> </start> <java class="com.jbpm.example.Printer" method="printHelloWorld" name="printHelloWorld"> <transition to="CheckDate"/> <transition to="theEnd"/> </java> <end name="theEnd" /> <state name="CheckDate"> <transition to="printHelloWorld"/> </state> </process>
5 在 项目的 src/groovy目录下创建一个类,代码如下所示:
package com.jbpm.example class Printer { public void printHelloWorld() { System.out.println("<---------------->"); System.out.println("&nbsp;&nbsp; HELLO WORLD!"); System.out.println("<---------------->"); } }
<jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <import resource="jbpm.tx.spring.cfg.xml" /> <!-- <import resource="jbpm.tx.hibernate.cfg.xml" /> --> </jbpm-configuration>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>
8 在resources.groovy中创建如下的Spring bean
beans = {
springHelper(org.jbpm.pvm.internal.processengine.SpringHelper){
jbpmCfg="jbpm.cfg.xml"
}
processEngine(springHelper:"createProcessEngine")
}
数据源还是在DataSource.groovy里配置,grails中怎么用就怎么配置,没有什么变化
def processEngine;
RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.createDeployment() .addResourceFromClasspath("helloWorld.jpdl.xml") .deploy();
10 按下面的方法开始一个流程实例
ExecutionService executionService = processEngine.getExecutionService(); executionService.startProcessInstanceByKey("helloWorld")
这样将按照流程描述中配置的那样,调用Printer 类中的printHelloWorld 方法
因为在使用jbpm的时候,还会时不进的报错,说是某个类的某个成员变量没有get方法,我查了一下jbpm的源代码,像报这种错的多数是因为这个字段的是boolean类型的,而boolean类型源码中是没有get方法的,只有is方法,而在grails中需要的是get方法,那没办法,只有编译jbpm源码,加上get方法了,像这样需要改的类有好几处,我也是边用遇到了边改的,用到现在grails与jbpm整合还是没什么问题的。
另外本人使用db2而其clob,blob默认是255bytes,不修改数据库会报错,需要修改JBPM4_LOB中clob和blob的长度.参考
http://www.bstek.com/wiki/pages/viewpage.action?pageId=7569647