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" class="org.jbpm.pvm.internal.processengine.SpringHelper" />

  <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
    <property name="dataSource" ref="dataSource" />
  </bean>

  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    <property name="dataSource" ref="dataSource" />
  </bean>

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" 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" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" 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提供的各种不同方式的组合。)

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值