1 概述
本文主要介绍如何将
JBPM+Struts+Spring+Hibernate整合在一块。并通过一个简单实例来说明。此实例为一个申请审批的简单流程,并将申请人和审批人记录到数据库中,流程为start----申请----审批----end,中间无退回,无分支,只是看一下
jbpm的流程设计,本文将
jbpm和struts/spring/hibernate结合在一块做为一个完整的项目来叙述。
通过
processdefinition.xml的可视图,可了解一下流程图:
2 环境
tomcat6.0+jdk1.5+eclips3.2
jbpm3.1.4
spring2.0
hibernate3
数据库:postgreSql8.1
jbpm提供了在eclipse下的一个可视化插件,通过它我们可以方便的定义工作流,介绍一下eclipse如何添加该插件?
打开jbpm-starters-kit-3.1.4\jbpm-designer\jbpm-gpd-feature目录,我们可以看到下面有一个eclipse文件夹,这里我们通过link的方式为eclipse添加该插件。
在
{eclipse_home}/link文件夹下新建jbpm-designer.link文件,用记事本打开该文件加入如下一行:
path=D:\\jbpm-starters-kit-3.1.4\\jbpm-designer\\jbpm-gpd-feature
后面的路径即为该插件的存放路径,根据个人情况修改。注意,这里的分隔符使用双斜杠
\\或者用单斜杠/。
3 项目总体结构
src部分
WebRoot部分:
4 要引入的jar包
很多jar包是从jbpm-starters-kit-3.1.4\jbpm-starters-kit-3.1.4\jbpm\build
和jbpm-starters-kit-3.1.4\jbpm-starters-kit-3.1.4\jbpm\lib中得到的
其中spring-modules-jbpm31.jar、postgresql-8.1-405.jdbc2.jar要下载
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
xmlns
=
"http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
version
=
"2.4"
xsi:schemaLocation
=
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
<
context-param
>
<
param
-name
>
webAppRootKey
</
param
-name
>
<
param
-value
>
/jbpm/
</
param
-value
>
</
context-param
>
<
context-param
>
<
param
-name
>
contextConfigLocation
</
param
-name
>
<
param-value
>
/WEB-INF/classes/applicationContext.xml
</
param-value
>
</
context-param
>
<
context-param
>
<
param
-name
>
log4jConfigLocation
</
param
-name
>
<
param
-value
>
/WEB-INF/classes/log4j.properties
</
param
-value
>
</
context-param
>
<
context-param
>
<
param
-name
>
log4jRefreshInterval
</
param
-name
>
<
param
-value
>
60000
</
param
-value
>
</
context-param
>
<
filter
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
filter-class
>
com.binghe.pub.SetCharacterEncodingFilter
</
filter-class
>
<
init-param
>
<
param
-name
>
encoding
</
param
-name
>
<
param
-value
>
GBK
</
param
-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
url
-pattern
>
/*
</
url
-pattern
>
</
filter-mapping
>
<
listener
>
<
listener-class
>
org.springframework.web.util.Log4jConfigListener
</
listener-class
>
</
listener
>
<
servlet
>
<
servlet
-name
>
action
</
servlet
-name
>
<
servlet-class
>
org.apache.struts.action.ActionServlet
</
servlet-class
>
<
init-param
>
<
param
-name
>
config
</
param
-name
>
<
param
-value
>
/WEB-INF/struts-config.xml
</
param
-value
>
</
init-param
>
<
init-param
>
<
param
-name
>
debug
</
param
-name
>
<
param
-value
>
3
</
param
-value
>
</
init-param
>
<
init-param
>
<
param
-name
>
detail
</
param
-name
>
<
param
-value
>
3
</
param
-value
>
</
init-param
>
<
load-on-startup
>
0
</
load-on-startup
>
</
servlet
>
<
servlet
>
<
servlet
-name
>
imageServlet
</
servlet
-name
>
<
servlet
-class
>
com.binghe.pub.ImageServlet
</
servlet
-class
>
</
servlet
>
<
servlet
-mapping
>
<
servlet
-name
>
action
</
servlet
-name
>
<
url
-pattern
>
*.do
</
url
-pattern
>
</
servlet
-mapping
>
<
servlet
-mapping
>
<
servlet
-name
>
imageServlet
</
servlet
-name
>
<
url
-pattern
>
/servlet/imageServlet
</
url
-pattern
>
</
servlet
-mapping
>
<
welcome-file-list
>
<
welcome-file
>
/apply.jsp
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
6 applicationContext.xml
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
beans
PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<
beans
>
<
bean
id
=
"dataSource"
class
=
"org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<
property
name
=
"driverClassName"
>
<
value
>
org.postgresql.Driver
</
value
>
</
property
>
<
property
name
=
"url"
>
<
value
>
jdbc:postgresql://localhost:5432/jbpmtest
</
value
>
</
property
>
<
property
name
=
"username"
>
<
value
>
admin
</
value
>
</
property
>
<
property
name
=
"password"
>
<
value
>
admin
</
value
>
</
property
>
</
bean
>
<
bean
id
=
"sessionFactory"
class
=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<
property
name
=
"dataSource"
>
<
ref
bean
=
"dataSource"
/>
</
property
>
<
property
name
=
"mappingLocations"
>
<
value
>
classpath
*:/org/jbpm/**/*.hbm.xml
</
value
>
</
property
>
<
property
name
=
"hibernateProperties"
>
<
props
>
<
prop
key
=
"hibernate.dialect"
>
org.hibernate.dialect.PostgreSQLDialect
</
prop
>
<
prop
key
=
"jdbc.fetch_size"
>
50
</
prop
>
<
prop
key
=
"jdbc.batch_size"
>
30
</
prop
>
<
prop
key
=
"hibernate.show_sql"
>
true
</
prop
>
<
prop
key
=
"hibernate.use_outer_join"
>
true
</
prop
>
<
prop
key
=
"hibernate.cglib.use_reflection_optimizer"
>
true
</
prop
>
</
props
>
</
property
>
</
bean
>
<!-- Transaction Manager -->
<
bean
id
=
"transactionManager"
class
=
"org.springframework.orm.hibernate3.HibernateTransactionManager"
>
<
property
name
=
"sessionFactory"
>
<
ref
local
=
"sessionFactory"
/>
</
property
>
</
bean
>
<!-- Transaction Interceptor -->
<
bean
id
=
"transactionInterceptor"
class
=
"org.springframework.transaction.interceptor.TransactionInterceptor"
dependency-check
=
"none"
>
<
property
name
=
"transactionManager"
>
<
ref
bean
=
"transactionManager"
/>
</
property
>
<
property
name
=
"transactionAttributes"
>
<
props
>
<
prop
key
=
"save*"
>
PROPAGATION_REQUIRED
</
prop
>
<
prop
key
=
"update*"
>
PROPAGATION_REQUIRED
</
prop
>
<
prop
key
=
"attachDirty*"
>
PROPAGATION_REQUIRED
</
prop
>
<
prop
key
=
"delete*"
>
PROPAGATION_REQUIRED
</
prop
>
<!-- default, readOnly -->
<
prop
key
=
"*"
>
PROPAGATION_REQUIRED,readOnly
</
prop
>
</
props
>
</
property
>
</
bean
>
<!-- reading jBPM process definitions -->
<
bean
id
=
"websaleWorkflow1"
class
=
"org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean"
>
<
property
name
=
"definitionLocation"
value
=
"classpath:/com/jpdl/simple/processdefinition.xml"
/>
</
bean
>
<!-- jBPM configuration-->
<
bean
id
=
"jbpmConfiguration"
class
=
"org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean"
>
<
property
name
=
"sessionFactory"
ref
=
"sessionFactory"
/>
<
property
name
=
"configuration"
value
=
"classpath:/jbpm.cfg.xml"
/>
<
property
name
=
"processDefinitions"
>
<
list