jbpm4.2与spring集成有点问题,直接跟据它自己的“开发指南”提供的方法是不能集成的。在官网查到的信息是发布4.2时,忘记更新集成spring的文件。不过4.3已经把该bug改过来了。下面是集成方法。
版本:
jbpm4.3
spring2.5.6
mysql5.1.40
直接从jbpm4.3自带的文件到src目录:
从jbpm-4.3"install"src"cfg"hibernate"jdbc复制mysql.hibernate.cfg.xml到src目录,文件名改为hibernate.cfg.xml。
从jbpm-4.3"install"src"cfg"spring复制applicationContext.xml到src目录。
从jbpm-4.3"install"src"cfg"jbpm复制spring.jbpm.cfg.xml到src目录,文件名改为jbpm.cfg.xml。
修改applicationContext.xml、hibernate.cfg.xml的数据库配置信息,jbpm4.3与spring的集成就完成了,可以自己写测试文件测试,集成非常容易。
不过在applicationContext.xml和hibernate.cfg.xml两个文件都要改数据库信息有点麻烦,所以只复制applicationContext.xml、spring.jbpm.cfg.xml两个文件到src目录,把hibernate.cfg.xml的配置整进spring的配置文件applicationContext.xml中。
applicationContext.xml
<
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:p
="http://www.springframework.org/schema/p"
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"
>
<
context:annotation-config
/>
<
bean
class
="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location
="hibernate.properties"
p:ignoreUnresolvablePlaceholders
="true"
/>
<
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
="dataSource"
ref
="dataSource"
/>
<
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
>
<
property
name
="hibernateProperties"
>
<
props
>
<
prop
key
="hibernate.dialect"
>
${dataSource.dialect}
</
prop
>
<
prop
key
="hibernate.hbm2ddl.auto"
>
${dataSource.hbm2ddl.auto}
</
prop
>
</
props
>
</
property
>
</
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
="${dataSource.driverClassName}"
/>
<
property
name
="url"
value
="${dataSource.url}"
/>
<
property
name
="username"
value
="${dataSource.username}"
/>
<
property
name
="password"
value
="${dataSource.password}"
/>
</
bean
>
</
beans
>
新建文件hibernate.properties,主要用来配置连接数据库信息
dataSource.password=123
dataSource.username=root
dataSource.databaseName=jbpmdb
dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.dialect=org.hibernate.dialect.MySQLInnoDBDialect
dataSource.serverName=localhost:3306
dataSource.url=jdbc:mysql://${dataSource.serverName}/${dataSource.databaseName}
dataSource.properties=user=${dataSource.username};databaseName=${dataSource.databaseName};serverName=${dataSource.serverName};password=${dataSource.password}
dataSource.hbm2ddl.auto=update
以后要改数据库配置信息也只在这个文件修改就可以了。
测试用的流程swing.jpdl.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
process
name
="swing"
xmlns
="http://jbpm.org/4.3/jpdl"
>
<
start
g
="94,64,48,48"
name
="start1"
>
<
transition
g
="-52,-22"
name
="A"
to
="A"
/>
</
start
>
<
task
assignee
="A"
g
="73,195,92,52"
name
="A"
>
<
transition
g
="-52,-22"
name
="B"
to
="B"
/>
</
task
>
<
task
assignee
="B"
g
="266,192,92,52"
name
="B"
>
<
transition
g
="-40,-21"
name
="end"
to
="end1"
/>
</
task
>
<
end
g
="290,327,48,48"
name
="end1"
/>
</
process
>
测试代码
public
class
Main {
public
static
void
main(String[] args) {
ClassPathXmlApplicationContext applicationContext
=
new
ClassPathXmlApplicationContext(
"
applicationContext.xml
"
);
applicationContext.start();
ProcessEngine processEngine
=
(ProcessEngine)applicationContext.getBean(
"
processEngine
"
);
ExecutionService executionService
=
processEngine.getExecutionService();
TaskService taskService
=
processEngine.getTaskService();
//
发布流程
String deploymentId
=
processEngine.getRepositoryService().createDeployment()
.addResourceFromClasspath(
"
resource/swing.jpdl.xml
"
).deploy();
System.out.println(
"
流程发布ID:
"
+
deploymentId);
//
启动一个流程实例
ProcessInstance processInstance
=
executionService.startProcessInstanceByKey(
"
swing
"
);
System.out.println(
"
流程实例ID:
"
+
processInstance.getId());
//
A处理任务
List
<
Task
>
taskList_A
=
taskService.findPersonalTasks(
"
A
"
);
System.out.println(
"
A待处理任务数:
"
+
taskList_A.size());
if
(taskList_A.size()
>
0
){
Task task
=
taskList_A.get(
0
);
taskService.completeTask(task.getId());
}
//
B处理任务
List
<
Task
>
taskList_B
=
taskService.findPersonalTasks(
"
B
"
);
System.out.println(
"
B待处理任务数:
"
+
taskList_B.size());
if
(taskList_B.size()
>
0
){
Task task
=
taskList_B.get(
0
);
taskService.completeTask(task.getId());
}
}
}
附件是完整的集成文件和测试代码,仅在spring2.5.6测试过,要运行该部分代码,需要添加jbpm4.3和spring的相关库文件。
源代码:jbpm4.3-spring