jbpm4.4整合spring2.5
2013-10-30 14:53
239 查看
搞了好几个小时总算运行成功了,记录一下吧。
首先下载jbpm4.4,解压出来备用。然后工程自己导入hibernate和spring的jar包以及配置文件。好了可以开始整合了!
整合的先后顺序是关键,下面按照顺序一步一步来设置:
1.首先jbpm是依赖数据库的,所以可以先创建数据库,我是mysql数据库,所以到jbpm-4.4\install\src\db\create中找到jbpm.mysql.create.sql创建文件导入mysql执行!
2.设置spring中hibernate的配置:
可以参考:jbpm-4.4\install\src\cfg\hibernate\spring中的mysql.hibernate.cfg.xml(具体见下面的spring配置文件applicationContext.xml)
3.设置事务,这里由于hibernate和ibatis必须用一个事务,所以使用了TransactionAwareDataSourceProxy来管理事务。(具体见下面的spring配置文件applicationContext.xml)
4.配置默认jbpm的cfg文件,在classpath下创建一个jbpm.cfg.xml,内容如下:
viewsource
print?
5.在spring配置文件中注入工作流引擎。(具体见下面的spring配置文件applicationContext.xml)
viewsource
print?
6.搞定以上配置文件后添加jbpm.jar,juel-api.jar,juel-engine.jar,juel-impl.jar,mail.jar,这里注意一下,可能有的朋友之后运行还会有错误如下:
java.lang.NoSuchMethodError:antlr.collections.AST.getLine()I
这是因为struts2的anltr-2.7.2.jar过旧导致的,我们为了省掉麻烦这里最好直接把struts2的antlr.jar去掉(windows---preferences---在文本框中搜索struts
2(中间有空格)---选择struts2---选择antlr---remove),然后重新到发布到服务器的lib目录下删除anltr-2.7.2.jar即可。
7.成功的关键就是applicationContext.xml了,这里把这个关键配置贴出来!
viewsource
print?
database.properties:
viewsource
print?
注意:这里会遇到一个类:com.xuyi.support.DynamicDataSource这类实现了多数据源管理。如下:
viewsource
print?
8.终于可以开始测试了,先创建一个发布用的xml放入classpath:
测试用的流程swing.jpdl.xml
viewsource
print?
然后写一个测试类进行测试:
viewsource
print?
一切顺利的话就可以看到具体打印了!!关于jbpm的xml专用设计插件,可以看我以前的
这篇文章。这样设计好xml就可以发布给jbpm进行工作流处理了。
转自:http://jsczxy2.iteye.com/blog/1236418
首先下载jbpm4.4,解压出来备用。然后工程自己导入hibernate和spring的jar包以及配置文件。好了可以开始整合了!
整合的先后顺序是关键,下面按照顺序一步一步来设置:
1.首先jbpm是依赖数据库的,所以可以先创建数据库,我是mysql数据库,所以到jbpm-4.4\install\src\db\create中找到jbpm.mysql.create.sql创建文件导入mysql执行!
2.设置spring中hibernate的配置:
可以参考:jbpm-4.4\install\src\cfg\hibernate\spring中的mysql.hibernate.cfg.xml(具体见下面的spring配置文件applicationContext.xml)
3.设置事务,这里由于hibernate和ibatis必须用一个事务,所以使用了TransactionAwareDataSourceProxy来管理事务。(具体见下面的spring配置文件applicationContext.xml)
4.配置默认jbpm的cfg文件,在classpath下创建一个jbpm.cfg.xml,内容如下:
01 | <? xml version = "1.0" encoding = "UTF-8" ?> |
02 |
03 | < jbpm-configuration > |
04 |
05 | < import resource = "jbpm.default.cfg.xml" /> |
06 | < import resource = "jbpm.businesscalendar.cfg.xml" /> |
07 | <!--<importresource="jbpm.tx.hibernate.cfg.xml"/>--> |
08 | < import resource = "jbpm.tx.spring.cfg.xml" /> |
09 | < import resource = "jbpm.jpdl.cfg.xml" /> |
10 | < import resource = "jbpm.bpmn.cfg.xml" /> |
11 | < import resource = "jbpm.identity.cfg.xml" /> |
12 |
13 | <!--Jobexecutorisexcludedforrunningtheexampletestcases.--> |
14 | <!--Toenabletimersandmessagesinproductionuse,thisshouldbeincluded.--> |
15 | <!-- |
16 | <importresource="jbpm.jobexecutor.cfg.xml"/> |
17 | --> |
18 |
19 | </ jbpm-configuration > |
1 | <!--jbpm4.4工作流--> |
2 | < bean id = "springHelper" class = "org.jbpm.pvm.internal.processengine.SpringHelper" /> |
3 | < bean id = "processEngine" factory-bean = "springHelper" factory-method = "createProcessEngine" /> |
java.lang.NoSuchMethodError:antlr.collections.AST.getLine()I
这是因为struts2的anltr-2.7.2.jar过旧导致的,我们为了省掉麻烦这里最好直接把struts2的antlr.jar去掉(windows---preferences---在文本框中搜索struts
2(中间有空格)---选择struts2---选择antlr---remove),然后重新到发布到服务器的lib目录下删除anltr-2.7.2.jar即可。
7.成功的关键就是applicationContext.xml了,这里把这个关键配置贴出来!
001 | <? xml version = "1.0" encoding = "UTF-8" ?> |
002 | < beans xmlns = "http://www.springframework.org/schema/beans" |
003 | xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:p = "http://www.springframework.org/schema/p" xmlns:context = "http://www.springframework.org/schema/context" |
004 | xmlns:aop = "http://www.springframework.org/schema/aop" |
005 | xsi:schemaLocation="http://www.springframework.org/schema/beans |
006 | http://www.springframework.org/schema/beans/spring-beans-2.5.xsd |
007 | http://www.springframework.org/schema/aop |
008 | http://www.springframework.org/schema/aop/spring-aop-2.5.xsd |
009 | http://www.springframework.org/schema/context |
010 | http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-autowire = "byName" > |
011 |
012 | < context:property-placeholder location = "classpath*:database.properties" /> |
013 |
014 |
015 |
016 | <!--jbpm4.4工作流--> |
017 | < bean id = "springHelper" class = "org.jbpm.pvm.internal.processengine.SpringHelper" /> |
018 | < bean id = "processEngine" factory-bean = "springHelper" factory-method = "createProcessEngine" /> |
019 |
020 | <!--dataSourceproxy配置代理管理事务--> |
021 | < bean id = "dataSource" |
022 | class = "org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy" |
023 | p:targetDataSource-ref = "dynamicDataSource" /> |
024 |
025 | <!--dataSource多数据源支持--> |
026 | < bean id = "dynamicDataSource" class = "com.xuyi.support.DynamicDataSource" > |
027 | < property name = "targetDataSources" > |
028 | < map key-type = "java.lang.String" > |
029 | < entry key = "dataSource" value-ref = "dataSourceJDBC" /> |
030 | </ map > |
031 | </ property > |
032 | </ bean > |
033 |
034 | <!--c3p0数据源配置--> |
035 | < bean id = "dataSourceJDBC" class = "com.mchange.v2.c3p0.ComboPooledDataSource" |
036 | destroy-method = "close" p:driverClass = "${jdbc.driverClass}" p:jdbcUrl = "${jdbc.jdbcUrl}" |
037 | p:user = "${jdbc.user}" p:password = "${jdbc.password}" p:initialPoolSize = "${c3p0.initialPoolSize}" |
038 | p:minPoolSize = "${c3p0.minPoolSize}" p:maxPoolSize = "${c3p0.maxPoolSize}" |
039 | p:acquireIncrement = "${c3p0.acquireIncrement}" p:maxIdleTime = "${c3p0.maxIdleTime}" |
040 | p:maxStatements = "${c3p0.maxStatements}" lazy-init = "true" /> |
041 |
042 |
043 | <!--hibernate-spring基本配置--> |
044 | < bean id = "sessionFactory" |
045 | class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" > |
046 | < property name = "dataSource" > |
047 | < ref bean = "dataSource" /> |
048 | </ property > |
049 | < property name = "hibernateProperties" > |
050 | < props > |
051 | < prop key = "hibernate.dialect" >org.hibernate.dialect.MySQLInnoDBDialect</ prop > |
052 | < prop key = "hibernate.hbm2ddl.auto" >update</ prop > |
053 | < prop key = "hibernate.format_sql" >true</ prop > |
054 | </ props > |
055 | </ property > |
056 | < property name = "mappingLocations" > |
057 | < list > |
058 | < value >classpath*:com/xuyi/modal/Creater.hbm.xml</ value > |
059 | < value >classpath*:com/xuyi/modal/Month.hbm.xml</ value > |
060 | < value >classpath*:com/xuyi/modal/Thing.hbm.xml</ value > |
061 | < value >classpath*:jbpm.repository.hbm.xml</ value > |
062 | < value >classpath*:jbpm.execution.hbm.xml</ value > |
063 | < value >classpath*:jbpm.history.hbm.xml</ value > |
064 | < value >classpath*:jbpm.task.hbm.xml</ value > |
065 | < value >classpath*:jbpm.identity.hbm.xml</ value > |
066 | </ list > |
067 | </ property > |
068 | <!--使用TransactionAwareDataSourceProxy管理事务与ibatis处于同一事务管理下--> |
069 | < property name = "useTransactionAwareDataSource" value = "true" ></ property > |
070 | </ bean > |
071 |
072 | <!--ibatis-spring配置--> |
073 | < bean id = "sqlMapClient" class = "org.springframework.orm.ibatis.SqlMapClientFactoryBean" > |
074 | < property name = "dataSource" ref = "dataSource" ></ property > |
075 | < property name = "configLocation" value = "classpath:sql-map-config.xml" ></ property > |
076 | </ bean > |
077 |
078 | <!--springtransaction事务管理--> |
079 | < bean id = "transactionManager" |
080 | class = "org.springframework.jdbc.datasource.DataSourceTransactionManager" > |
081 | < property name = "dataSource" ref = "dataSource" /> |
082 | </ bean > |
083 |
084 |
085 | <!--事务代理拦截器的配置--> |
086 | < bean id = "transactionProxy" abstract = "true" |
087 | class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" > |
088 | < property name = "transactionManager" > |
089 | < ref bean = "transactionManager" /> |
090 | </ property > |
091 | < property name = "transactionAttributes" > |
092 | < props > |
093 | < prop key = "get*" >PROPAGATION_REQUIRED,readOnly</ prop > |
094 | < prop key = "find*" >PROPAGATION_REQUIRED,readOnly</ prop > |
095 | < prop key = "*" >PROPAGATION_REQUIRED</ prop > |
096 | </ props > |
097 | </ property > |
098 | </ bean > |
099 |
100 | </ beans > |
01 | jdbc.driverClass=com.mysql.jdbc.Driver |
02 | jdbc.jdbcUrl=jdbc:mysql://localhost:3306/myweb |
03 | jdbc.user=root |
04 | jdbc.password= pwd |
05 |
06 |
07 | c3p0.initialPoolSize=1 |
08 | c3p0.minPoolSize=1 |
09 | c3p0.maxPoolSize=10 |
10 | c3p0.acquireIncrement=5 |
11 | c3p0.maxIdleTime=1800 |
12 | c3p0.maxStatements=0 |
01 | package
|
02 |
03 | import
|
04 |
05 | public class DynamicDataSource extends AbstractRoutingDataSource{ |
06 |
07 | private static ThreadLocal<String>local= new ThreadLocal<String>(); |
08 |
09 | @Override |
10 | protected ObjectdetermineCurrentLookupKey(){ |
11 | return local.get()== null ? "dataSource"
|
12 | } |
13 |
14 | //--------------------------------------------------------------------------------------------------- |
15 |
16 | /** |
17 | *设置数据源路径 |
18 | */ |
19 | public static void
|
20 | if (route== null
"" )){ |
21 | route= "dataSource" ; |
22 | } |
23 | local.set(route); |
24 | } |
25 | } |
测试用的流程swing.jpdl.xml
01 | <? xml version = "1.0" encoding = "UTF-8" ?> |
02 | < process name = "swing" xmlns = "http://jbpm.org/4.3/jpdl" > |
03 | < start g = "94,64,48,48" name = "start1" > |
04 | < transition g = "-52,-22" name = "A" to = "A" /> |
05 | </ start > |
06 | < task assignee = "A" g = "73,195,92,52" name = "A" > |
07 | < transition g = "-52,-22" name = "B" to = "B" /> |
08 | </ task > |
09 | < task assignee = "B" g = "266,192,92,52" name = "B" > |
10 | < transition g = "-40,-21" name = "end" to = "end1" /> |
11 | </ task > |
12 | < end g = "290,327,48,48" name = "end1" /> |
13 | </ process > |
01 | package
|
02 |
03 | import
|
04 |
05 | import
|
06 | import
|
07 | import
|
08 | import
|
09 | import
|
10 | import
|
11 |
12 | public class TestJbpm{ |
13 | public static void
|
14 | ClassPathXmlApplicationContextapplicationContext= new ClassPathXmlApplicationContext( "applicationContext.xml" ); |
15 | applicationContext.start(); |
16 | ProcessEngineprocessEngine=(ProcessEngine)applicationContext.getBean( "processEngine" ); |
17 | ExecutionServiceexecutionService=processEngine.getExecutionService(); |
18 | TaskServicetaskService=processEngine.getTaskService(); |
19 |
20 | //发布流程 |
21 | StringdeploymentId=processEngine.getRepositoryService().createDeployment() |
22 | .addResourceFromClasspath( "swing.jpdl.xml" ).deploy(); |
23 | System.out.println( "流程发布ID:" +deploymentId); |
24 |
25 | //启动一个流程实例 |
26 | ProcessInstanceprocessInstance=executionService.startProcessInstanceByKey( "swing" ); |
27 | System.out.println( "流程实例ID:" +processInstance.getId()); |
28 |
29 |
30 | //A处理任务 |
31 | List<Task>taskList_A=taskService.findPersonalTasks( "A" ); |
32 | System.out.println( "A待处理任务数:" +taskList_A.size()); |
33 | if (taskList_A.size()> 0 ){ |
34 | for (Tasktask:taskList_A){ |
35 | System.out.println(task.getId()); |
36 | taskService.completeTask(task.getId()); |
37 | } |
38 | } |
39 |
40 | //B处理任务 |
41 | List<Task>taskList_B=taskService.findPersonalTasks( "B" ); |
42 | System.out.println( "B待处理任务数:" +taskList_B.size()); |
43 | if (taskList_B.size()> 0 ){ |
44 | for (Tasktask:taskList_B){ |
45 | System.out.println(task.getId()); |
46 | taskService.completeTask(task.getId()); |
47 | } |
48 | } |
49 |
50 | } |
51 | } |
在Myeclipse8.6安装JBPM插件
这篇文章。这样设计好xml就可以发布给jbpm进行工作流处理了。转自:
相关文章推荐
- java内存查看与分析
- Java简单文件传输 socket简单文件传输示例
- java使用方法总结
- java.sql.SQLException: The Network Adapter could not establish the connection
- javaMail2种方式实现,并读取html格式邮件模板
- Java其实很简单(1)----好的心态是成功的一半
- web项目的乱码解决方法
- Spring AOP(转载)
- 使用zxing生成嵌图片的二维码【java】
- java.lang.NoClassDefFoundError: org/jaxen/JaxenException
- 提升性能 Java程序优化的一些最佳实践
- OAuth授权的Java实现详解
- Java NIO API详解
- jbpm+spring
- Java中通过SimpleDateFormat格式化当前时间:/** 输出格式:20060101010101001**/
- Java基本开发环境搭建 .
- java垃圾回收精华
- flex4与Java交互的三种通信方式
- 严重: IOException while loading persisted sessions: java.io.InvalidClassException:
- 利用Spring的AbstractRoutingDataSource解决多数据源的问题