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

 

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

 

Configuration.getProcessEngine()的代码如下:

 

Java代码
  1.   
  2. public static ProcessEngine getProcessEngine() {   
  3.   if (singleton == null) {   
  4.     synchronized (Configuration.class) {   
  5.       if (singleton == null) {   
  6.         singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();   
  7.       }   
  8.     }   
  9.   }   
  10.   return Configuration.singleton;   
  11. }    

 (虽然这一段代码可能会有“双重检查锁定”失败的问题,但是不影响到分析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代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <jbpm-configuration>  
  4.   
  5.   <import resource="jbpm.default.cfg.xml" />  
  6.   <import resource="jbpm.tx.spring.cfg.xml" />  
  7.   <import resource="jbpm.jpdl.cfg.xml" />  
  8.   <import resource="jbpm.bpmn.cfg.xml" />  
  9.   <import resource="jbpm.identity.cfg.xml" />  
  10.   <import resource="jbpm.businesscalendar.cfg.xml" />  
  11.   <import resource="jbpm.console.cfg.xml" />  
  12.   <import resource="jbpm.jobexecutor.cfg.xml" />  
  13.      
  14.   <process-engine-context>  
  15.     <string name="spring.cfg" value="applicationContext.xml" />  
  16.   </process-engine-context>  
  17.   
  18. </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代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"  
  4.   xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  6.   xsi:schemaLocation="   
  7.     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  8.     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  9.     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd   
  10.     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  11.   
  12.   <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />  
  13.   
  14.   <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />  
  15.   
  16.   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  17.     <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />  
  18.     <property name="dataSource" ref="dataSource" />  
  19.   </bean>  
  20.   
  21.   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  22.     <property name="sessionFactory" ref="sessionFactory" />  
  23.     <property name="dataSource" ref="dataSource" />  
  24.   </bean>  
  25.   
  26.   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  27.     <property name="driverClassName" value="@jdbc.driver@" />  
  28.     <property name="url" value="@jdbc.url@" />  
  29.     <property name="username" value="@jdbc.username@" />  
  30.     <property name="password" value="@jdbc.password@" />  
  31.   </bean>  
  32.   
  33. </beans>  
 
  

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

 

Xml代码
  1. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  2.   <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />  
  3.   <property name="dataSource" ref="dataSource" />  
  4. </bean>  
   

 

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

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

以oracle的配置文件为例:

 

Xml代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <!DOCTYPE hibernate-configuration PUBLIC   
  4.   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"   
  5.   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
  6.   
  7. <hibernate-configuration>  
  8.   <session-factory>  
  9.     <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>  
  10.     <property name="hibernate.format_sql">true</property>  
  11.   
  12.     <mapping resource="jbpm.repository.hbm.xml" />  
  13.     <mapping resource="jbpm.execution.hbm.xml" />  
  14.     <mapping resource="jbpm.history.hbm.xml" />  
  15.     <mapping resource="jbpm.task.hbm.xml" />  
  16.     <mapping resource="jbpm.identity.hbm.xml" />  
  17.   </session-factory>  
  18. </hibernate-configuration>  

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

 

这样完成了jBPM4.4和spring的结合

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值