首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 相關知識

jBPM 4.0 整合 Spring 實戰配置全記錄

     編輯:Java 相關知識

記錄 jBPM 4.0 與 Spring 2.5.6 原生整合的完整配置結構與關鍵文件,採用 SpringConfiguration 載入 jBPM 設定,由 Spring 管理 ProcessEngine 及各服務 Bean。

資源目錄結構

src/resources
├── jbpm/
│   ├── jbpm.cfg.xml
│   ├── jbpm.default.cfg.xml
│   ├── jbpm.tx.hibernate.cfg.xml
│   ├── jbpm.mail.properties
│   ├── jbpm.mail.templates.examples.xml
│   └── logging.properties
└── spring/
    ├── applicationContext-jbpm.xml
    └── applicationContext-hibernate.xml

核心配置文件解析

1. jbpm.cfg.xml —— 總入口,匯入子配置並啟用 Spring 事務攔截器

<jbpm-configuration>
  <import resource="jbpm/jbpm.default.cfg.xml" />
  <import resource="jbpm/jbpm.tx.hibernate.cfg.xml" />
  <import resource="jbpm.jpdl.cfg.xml" />
  <import resource="jbpm.identity.cfg.xml" />
  <import resource="jbpm/jbpm.mail.templates.examples.xml" />
  <process-engine-context>
    <command-service>
      <retry-interceptor />
      <environment-interceptor />
      <spring-transaction-interceptor />  <!-- 關鍵:接管事務 -->
    </command-service>
  </process-engine-context>
  <transaction-context>
    <transaction />
    <hibernate-session />
  </transaction-context>
</jbpm-configuration>

2. jbpm.default.cfg.xml —— 服務組件、腳本引擎、郵件模板、業務日曆等基礎設施

定義 repository-service、execution-service、task-service 等核心服務;配置 JUEL 腳本引擎;內建任務通知/提醒郵件模板;定義工作日曆與假期。

3. jbpm.tx.hibernate.cfg.xml —— 事務與 Hibernate Session 綁定 Spring 管理的當前 Session

<jbpm-configuration>
  <process-engine-context>
    <command-service>
      <spring-transaction-interceptor current="true" />  <!-- 使用 Spring 當前事務 -->
    </command-service>
  </process-engine-context>
  <transaction-context>
    <hibernate-session current="true"/>  <!-- 綁定 Spring 的 Current Session -->
  </transaction-context>
</jbpm-configuration>

4. applicationContext-jbpm.xml —— Spring 裝配 jBPM 核心 Bean

<beans>
  <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
    <constructor-arg value="jbpm/jbpm.cfg.xml" />
  </bean>
  <bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
</beans>

5. applicationContext-hibernate.xml (片段) —— SessionFactory 掃描 jBPM 映射文件

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="mappingResources">
    <list>
      <value>jbpm.repository.hbm.xml</value>
      <value>jbpm.execution.hbm.xml</value>
      <value>jbpm.history.hbm.xml</value>
      <value>jbpm.task.hbm.xml</value>
      <value>jbpm.identity.hbm.xml</value>
    </list>
  </property>
</bean>

關鍵依賴提示

確保 classpath 包含:jbpm-pvm.jar、jbpm-jpdl.jar、spring-orm.jar、hibernate3.jar、juel-api/impl.jar 及資料庫驅動。缺包將導致 NoClassDefFoundError 或映射異常。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved