---
title: "JBPM的使用心得"
author: "wei5201"
date: "2011-03-01T15:09:53Z"
tags: []
categories: ["企业架构"]
slug: "jbpm"
draft: false
lastmod: "2011-04-20T18:05:22Z"
id: 935656
url: "https://wei5201.iteye.com/blog/935656"
---

首先是安装4.4版本的插件.通过使用links方式安装好了插件,前提是7.0以上版本的myeclipse吧. 插件见附件jbpm_jpd_site.zip!

之后,由于插件对于中文支持不是太好,经常二次打开后,乱码,故修改myeclipse.ini,在最后加上 '-Dfile.encoding=UTF-8'. 这样做使得jbpm配置文件不再乱码.但是导致tomcat控制台中文乱码,再次修改tomcat目录下/bin/catalina.bat文件,在set JAVA OPT=XXX 这段话最后也加上'-Dfile.encoding=UTF-8' .  这样就搞定乱码问题了!
**一  ssh整合jbpm了,其实很简单:**
1.**首先写下jbpm在spring中的配置**:


```java
<?xml version="1.0" encoding="UTF-8"?>
<beans
	xmlns="http://www.springframework.org/schema/beans"
	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.0.xsd">
	
	
	<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">   
        <property name="jbpmCfg" value="jbpm.cfg.xml" />   
	</bean>   
	
	<bean id="processEngine" factory-bean="springHelper"  factory-method="createProcessEngine" />  

	<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />   
  
    <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />   
  
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>   
  
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>   
  
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>   
	
	
	
	<bean id="jbpmService" class="com.creditease.engine.flow.jbpm.service.JBPMServiceImpl" parent="baseService">   
        <property name="repositoryService" ref="repositoryService" />  
        <property name="taskService" ref="taskService" />  
        <property name="executionService" ref="executionService" /> 
        <property name="jbpmLogService" ref="jbpmLogService" /> 
	</bean>  
	
	<bean id="jbpmLogService" class="com.creditease.engine.flow.jbpm.log.JbpmLogServiceImpl" parent="baseService">   
	</bean>  
	
</beans>
```


jbpmService是自己封装的工作流服务类,既然是做成组件,那当然业务对象里不能参合工作流的东西了.这个service一会再讲.
jbpmLogService是是用来做历史服务的,详细记录了什么人什么时间执行了什么流程,成功执行还是回退到某个流程.

**jbpm.cfg.xml这个文件也是必须的,每天可连不上数据库哦:**


```java
<?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" />   


  <!-- 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" />
  -->

</jbpm-configuration>

```


**最后,事务控制别忘了做哦:**

```java
<!-- 事务控制  -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>			
			<tx:method name="saveOrUpdate" propagation="REQUIRED" />
			<tx:method name="delete" propagation="REQUIRED" />
			<tx:method name="get" read-only="true" />
			<tx:method name="count" read-only="true" />
			<tx:method name="find" read-only="true" />
		</tx:attributes>
	</tx:advice>	
	
	<tx:advice id="jbpmAdvice" transaction-manager="transactionManager">
		<tx:attributes>			
			<tx:method name="*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>	
	
	<aop:config>
		<aop:pointcut id="jbpmPointcut"
			expression="execution(* com.creditease.engine.**.service.*.*(..))" />
		<aop:pointcut id="servicePointcut"
			expression="execution(* com.creditease.clic.**.service.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" />
		<aop:advisor advice-ref="jbpmAdvice" pointcut-ref="jbpmPointcut" />
	</aop:config>

```


**jbpmService最好注入在其他服务类中,使用时,调用其他服务类中带事务的方法也就保持了事务一致性了.**

这样我们经过以上的一些配置,jbpm与sping就完成了结合的工作了.

二  jbpmService服务类,**下班了,下次有空再写吧.**
  


**目前在做接口,供其他开发人员调用,也就是说组件化jbpm.做完了,再上来说,继续忙!**