在grails中应用jbpm4

 

Grails 底层是 spring 的 mvc, jbpm4 也内置了 与 spring 集成的支持,因此 在 Grails 中集成进 jbpm4 还是比较简单的。

 

  1. 拷贝jbpm4.jar 及 依赖包 到 应用的 lib 下
  2. 将 jbpm.defaut.xml 改名为 jbpm.cfg.xml 拷贝到 grails-app/conf 目录下(可以是任意其它文件名)
  3. 在 resources.groovy(grails-app/conf/spring目录下,如果没有则新建一个) 中添加
    	jbpmConfiguration(org.jbpm.pvm.internal.cfg.SpringConfiguration, "jbpm.cfg.xml"){
    	}
     
  4. 同样预先配置好需要用的service  
        processEngine(org.jbpm.api.ProcessEngine){ bean ->
    	    bean.factoryBean = "jbpmConfiguration"
    	    bean.factoryMethod = "buildProcessEngine"
        }
        repositoryService(org.jbpm.api.RepositoryService){ bean->
    	    bean.factoryBean = "processEngine"
    	    bean.factoryMethod = "getRepositoryService"
        }
        executionService(org.jbpm.api.ExecutionService){ bean->
    	    bean.factoryBean = "processEngine"
    	    bean.factoryMethod = "getExecutionService"
        }
        commandService(org.jbpm.pvm.internal.cmd.CommandService, org.jbpm.pvm.internal.cmd.CommandService.class){ bean->
            bean.factoryBean = "processEngine"
            bean.factoryMethod = "get"
        }
    
        taskService(org.jbpm.api.TaskService){ bean->
            bean.factoryBean = "processEngine"
            bean.factoryMethod = "getTaskService"
        }
    
        historyService(org.jbpm.api.HistoryService){ bean->
            bean.factoryBean = "processEngine"
            bean.factoryMethod = "getHistoryService"
        }
    
        identityService(org.jbpm.api.IdentityService){ bean->
            bean.factoryBean = "processEngine"
            bean.factoryMethod = "getIdentityService"
        }
        managementService(org.jbpm.api.ManagementService){ bean->
            bean.factoryBean = "processEngine"
            bean.factoryMethod = "getManagementService"
        }
     
  5. 在jbpm.cfg.xml 中 标准事务拦截器修改为 spring 的事务拦截器
          <!--
          <standard-transaction-interceptor />
          -->
          <spring-transaction-interceptor current="true" />
     
  6. 同样在jbpm.cfg.xml 中,将 原来 transaction-context 中的 transaction 改为 hibernate session
        <!--
        <transaction />
        -->
        <hibernate-session current="true" close="false"/>
     
  7. 在hibernate.cfg.xml中(grails-app/conf/hibernate目录下,没有则新建一个),添加 jbpm 的 cfg 文件
    <!DOCTYPE hibernate-configuration SYSTEM
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
            <mapping resource="jbpm.execution.hbm.xml" />
            <mapping resource="jbpm.repository.hbm.xml" />
            <mapping resource="jbpm.jpdl.hbm.xml" />
            <mapping resource="jbpm.task.hbm.xml" />
            <mapping resource="jbpm.history.hbm.xml" />
        </session-factory>
    </hibernate-configuration>
  8. 注释掉对jbpm 对 hibernate 的配置
        <!--
        <hibernate-configuration>
          <cfg resource="jbpm.hibernate.cfg.xml" />
        </hibernate-configuration>
    
        <hibernate-session-factory />
        -->
     

配置完成

这样配置完后,jbpm不再采用自己的事务,而是采用 spring 管理的事务,即要求 事务必须已经存在,因此在 grails中使用时,对 jbpm service 调用 必须在 grails 的 service 中进行。

 

完整的 参考 jbpm.cfg.xml 内容如下

<?xml version="1.0" encoding="UTF-8"?>

<jbpm-configuration>
  <import resource="jbpm.jpdl.cfg.xml" />
  <import resource="jbpm.identity.cfg.xml" />

  <!-- Job executor is excluded for running the example test cases. -->
  <!-- To enable timers and messages in production use, this should be included. -->
  <!--
  <import resource="jbpm.jobexecutor.cfg.xml" />
  -->
    <!--
  <import resource="jbpm.mail.templates.examples.xml" />
    -->


  <process-engine-context>

    <repository-service />
    <repository-cache />
    <execution-service />
    <history-service />
    <management-service />
    <identity-service />
    <task-service />
<!--
<hibernate-configuration>
<cfg resource="jbpm.hibernate.cfg.xml" />
</hibernate-configuration>

<hibernate-session-factory />
-->

<command-service> <retry-interceptor /> <environment-interceptor />
<!--
<standard-transaction-interceptor />
-->
<spring-transaction-interceptor current="true" />

</command-service> <script-manager default-expression-language="juel" default-script-language="juel" read-contexts="execution, environment, process-engine" write-context=""> <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" /> </script-manager> <authentication /> <id-generator /> <types resource="jbpm.variable.types.xml" /> <address-resolver /> <business-calendar> <monday hours="9:00-12:00 and 12:30-17:00"/> <tuesday hours="9:00-12:00 and 12:30-17:00"/> <wednesday hours="9:00-12:00 and 12:30-17:00"/> <thursday hours="9:00-12:00 and 12:30-17:00"/> <friday hours="9:00-12:00 and 12:30-17:00"/> <holiday period="01/07/2008 - 31/08/2008"/> </business-calendar> <mail-template name='task-notification'> <to users="${task.assignee}"/> <subject>${task.name}</subject> <text><![CDATA[Hi ${task.assignee}, Task "${task.name}" has been assigned to you. ${task.description} Sent by JBoss jBPM ]]></text> </mail-template> <mail-template name='task-reminder'> <to users="${task.assignee}"/> <subject>${task.name}</subject> <text><![CDATA[Hey ${task.assignee}, Do not forget about task "${task.name}". ${task.description} Sent by JBoss jBPM ]]></text> </mail-template> </process-engine-context> <transaction-context> <repository-session /> <db-session /> <message-session /> <timer-session /> <history-session /> <mail-session> <mail-server> <session-properties resource="jbpm.mail.properties" /> </mail-server> </mail-session>
<!--
<transaction />
-->
<hibernate-session current="true" close="false"/>

</transaction-context> </jbpm-configuration>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值