读书人

jBPM4.4:配置(包括和Spring的调整

发布时间: 2013-11-08 17:52:14 作者: rapoo

jBPM4.4:配置(包括和Spring的整合,和Hibernate配置)

jBPM4.4,获取ProcessEngine是通过Configuration.getProcessEngine()中获取的。

?

Configuration.getProcessEngine()的代码如下:

?

  /** get the singleton ProcessEngine that is created from the default   * configuration file 'jbpm.cfg.xml'. */  public static ProcessEngine getProcessEngine() {    if (singleton == null) {      synchronized (Configuration.class) {        if (singleton == null) {          singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();        }      }    }    return Configuration.singleton;  }

?

?(虽然这一段代码可能会有“双重检查锁定”失败的问题,但是不影响到分析jBPM的配置 -- 详见IBM04年的文章:双重检查锁定及单例模式)

?

系统缺省的加载jbpm.cfg.xml,作为主配置文件。

?

在jBPM4.4的install/src/cfg中,带了几套配置文件的样板。

在cfg中:有几个目录:

hibernate:采用hibernate时候的配置(其中还分为好几种方式的数据源方式:datasource/jdbc/spring/tomcat)

jbpm ? ? ?:主配置文件的样板(分为:采用jta/spring/standalone--这种方式直接配置hibernate)

logging ? : logging的几种配置法

mail ? ? ? : 邮件的配置样板

spring ? ?: 如果使用到spring的时候,applicationcontext.xml的样板

?

在jbpm目录中,拿一个样板来讲:spring.jbpm.cfg.xml

?

<?xml version="1.0" encoding="UTF-8"?><jbpm-configuration>  <import resource="jbpm.default.cfg.xml" />  <import resource="jbpm.tx.spring.cfg.xml" />  <import resource="jbpm.jpdl.cfg.xml" />  <import resource="jbpm.bpmn.cfg.xml" />  <import resource="jbpm.identity.cfg.xml" />  <import resource="jbpm.businesscalendar.cfg.xml" />  <import resource="jbpm.console.cfg.xml" />  <import resource="jbpm.jobexecutor.cfg.xml" />    <process-engine-context>    <string name="spring.cfg" value="applicationContext.xml" />  </process-engine-context></jbpm-configuration>
?

?

对于3种不同的配置,就是在第二个配置项上有差异,其余部分都是一样的。

spring: ? ? ?<import resource="jbpm.tx.spring.cfg.xml" />

jta ? ? : ? ? ?<import resource="jbpm.tx.jta.cfg.xml" />

standalone:?<import resource="jbpm.tx.hibernate.cfg.xml" />

?

这几个文件都在{jBPM4.4}的src目录中。

现在要做的和spring结合起来,因此在自己项目中,采用第一个配置:

?

其实这3个文件的差别也是不大,主要在于配置transaction-context上,而且如果采用spring的话,hibernate的配置进了spring的配置文件,因此在jbpm.tx.spring.cfg中,不需要有hibernate的配置,而另外2种方式,都要声明hibernate配置采用哪个文件。

?

样例的applicationcontext.xml:

?

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"  xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  <bean id="springHelper" />  <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />  <bean id="sessionFactory" value="classpath:jbpm.hibernate.cfg.xml" />    <property name="dataSource" ref="dataSource" />  </bean>  <bean id="transactionManager" ref="sessionFactory" />    <property name="dataSource" ref="dataSource" />  </bean>  <bean id="dataSource" value="@jdbc.driver@" />    <property name="url" value="@jdbc.url@" />    <property name="username" value="@jdbc.username@" />    <property name="password" value="@jdbc.password@" />  </bean></beans>
?

?

数据库的配置在spring配置文件中,单独的有一段:

?

  <bean id="sessionFactory" value="classpath:jbpm.hibernate.cfg.xml" />    <property name="dataSource" ref="dataSource" />  </bean>
?

?

而且数据源配置在spring的配置文件中,因此在hibernate的配置文件中,就不需要配置数据源了。

hibernate的配置文件:在{JBPM4.4}/install/src/cfg/hibernate/spring中:

以oracle的配置文件为例:

<?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>    <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>    <property name="hibernate.format_sql">true</property>    <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>

?在hibernate的配置文件中,见不到数据库的连接配置信息了,这样数据库连接可以在spring中统一配置,避免了在一个系统中,多处配置数据库连接的情况。

?

这样完成了jBPM4.4和spring的结合。(好像自己没做什么,就是看了一下jBPM提供的各种不同方式的组合。)

?

?

?

?

?

读书人网 >编程

热点推荐