- 浏览: 764497 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (208)
- Java (77)
- JavaScript (16)
- UML (1)
- Spring (24)
- Hibernate (11)
- J2EE部署 (18)
- 操作系统 (13)
- struts (11)
- jsp (3)
- J2EE (34)
- 数据库 (22)
- tomcat (4)
- apache (2)
- MyEclipse (13)
- Linux (14)
- Ext (6)
- Weblogic (2)
- 数据库 Oracle 空表导出 (1)
- Oracle (3)
- 编码 乱码 (1)
- 多线程 (5)
- jQuery (2)
- Apache Mina (1)
- ibatis (6)
- abator (1)
- svn (1)
- jvm (1)
- ERwin (2)
- mysql (2)
- ant (1)
- memcache (1)
- dubbo (1)
- PowerDesigner (1)
最新评论
-
di1984HIT:
Shallow heap & Retained heap -
tinguo002:
非常感谢 , 太棒了。
Spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法 -
白天看黑夜:
Apache Mina Server 2.0 中文参考手册(带 ...
Apache Mina – 简单的客户端/服务端应用示例 -
wumingxingzhe:
好文
Shallow heap & Retained heap -
di1984HIT:
学习了!!
工作流(Workflow)和BPM的不同
Activiti 5.6与Spring整合也比较简单,其基本思想就是,通过Spring的IOC容器来管理Activiti的流程引擎实例以及相关服务,可见,主要是基于Activiti在与Spring整合上努力上,做好配置即可。这里基于前面的<receiveTask>的例子来进行,可以参考:Activiti 5.6:流程活动自动与手工触发执行,简单的流程,如图所示:
Activiti 5.6与Spring整合,默认使用的配置文件为activiti-context.xml,当然可以在实际使用的时候覆盖掉默认的配置,或者增加自己的其他的Spring的配置。
我们也命名为activiti-context.xml,内容(安装Activiti 5.6的时候,实例工程中已经附带)如下所示:
这里面,我把Activiti 5.6默认工程中有关JPA的部分配置删除了,其实通过这个就可以初始化Activiti引擎实例。为了测试方便,将获取服务的实现抽象出来,同时使用Spring自带的与JUnit4集成的工具(AbstractTransactionalJUnit4SpringContextTests)。我们的实现类为AbstractSpringTest,代码如下所示:
上面,将classpath:activiti-context.xml在测试的时候进行加载,这样,在测试的子类中,只需要将其他的相关Spring配置单独加载即可,业务配置与流程配置分开,便于维护。
具体测试用例,这里实现了一个简单的Spring Bean,配置文件为mySpringContext.xml,如下所示:
Spring Bean的实现,代码如下所示:
下面,看看我们具体的测试用例,实现代码如下所示:
运行程序,结果信息如下所示:
Spring版本3.0.3
Activiti 5.6与Spring整合,默认使用的配置文件为activiti-context.xml,当然可以在实际使用的时候覆盖掉默认的配置,或者增加自己的其他的Spring的配置。
我们也命名为activiti-context.xml,内容(安装Activiti 5.6的时候,实例工程中已经附带)如下所示:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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.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-3.0.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="org.h2.Driver" /> <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="dataSource" /> <property name="transactionManager" ref="transactionManager" /> <property name="databaseSchemaUpdate" value="true" /> <property name="mailServerHost" value="localhost" /> <property name="mailServerPort" value="5025" /> <property name="jpaHandleTransaction" value="true" /> <property name="jpaCloseEntityManager" value="true" /> <property name="jobExecutorActivate" value="false" /> </bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" /> <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /> <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /> <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" /> </beans>
这里面,我把Activiti 5.6默认工程中有关JPA的部分配置删除了,其实通过这个就可以初始化Activiti引擎实例。为了测试方便,将获取服务的实现抽象出来,同时使用Spring自带的与JUnit4集成的工具(AbstractTransactionalJUnit4SpringContextTests)。我们的实现类为AbstractSpringTest,代码如下所示:
package org.shirdrn.workflow.activiti; import java.util.logging.Logger; import org.activiti.engine.HistoryService; import org.activiti.engine.ManagementService; import org.activiti.engine.ProcessEngine; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.junit.After; import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; @ContextConfiguration("classpath:activiti-context.xml") public abstract class AbstractSpringTest extends AbstractTransactionalJUnit4SpringContextTests { @SuppressWarnings("unused") private final Logger log = Logger.getLogger(AbstractSpringTest.class.getName()); @SuppressWarnings("unused") @Autowired private ProcessEngine processEngine; @Autowired protected RepositoryService repositoryService; @Autowired protected RuntimeService runtimeService; @Autowired protected TaskService taskService; @Autowired protected HistoryService historyService; @Autowired protected ManagementService managementService; protected String deploymentId; public AbstractSpringTest() { super(); } @Before public void initialize() throws Exception { beforeTest(); } @After public void clean() throws Exception { afterTest(); } protected abstract void beforeTest() throws Exception; protected abstract void afterTest() throws Exception; }
上面,将classpath:activiti-context.xml在测试的时候进行加载,这样,在测试的子类中,只需要将其他的相关Spring配置单独加载即可,业务配置与流程配置分开,便于维护。
具体测试用例,这里实现了一个简单的Spring Bean,配置文件为mySpringContext.xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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.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-3.0.xsd"> <bean id="mySpringBean" class="org.shirdrn.workflow.activiti.spring.MySpringBean"> <property name="id" value="65536" /> <property name="name" value="shirdrn" /> </bean> </beans>
Spring Bean的实现,代码如下所示:
package org.shirdrn.workflow.activiti.spring; import java.io.Serializable; public class MySpringBean implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "MySpringBean[id="+ id + ",name=" + name + "]"; } }
下面,看看我们具体的测试用例,实现代码如下所示:
package org.shirdrn.workflow.activiti.spring; import java.util.HashMap; import java.util.List; import java.util.Map; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.Execution; import org.activiti.engine.runtime.ProcessInstance; import org.junit.Test; import org.shirdrn.workflow.activiti.AbstractSpringTest; import org.shirdrn.workflow.activiti.subprocess.Merchant; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration({ "classpath:org/shirdrn/workflow/activiti/spring/mySpringContext.xml"}) public class ActivitiWithSpringTest extends AbstractSpringTest { @Autowired private MySpringBean mySpringBean; @Override protected void beforeTest() throws Exception { Deployment deployment = repositoryService .createDeployment() .addClasspathResource( "diagrams/Task.ReceiveTask.bpmn20.xml") .deploy(); deploymentId = deployment.getId(); } @Override protected void afterTest() throws Exception { repositoryService.deleteDeployment(deploymentId, true); } @Test public void triggerMyProcess() { // prepare data packet Map<String, Object> variables = new HashMap<String, Object>(); Map<String, Object> subVariables = new HashMap<String, Object>(); variables.put("maxTransCount", 1000000); variables.put("merchant", new Merchant("ICBC")); variables.put("protocol", "UM32"); variables.put("repository", "10.10.38.99:/home/shirdrn/repository"); variables.put("in", subVariables); variables.put("out", new HashMap<String, Object>()); // start process instance ProcessInstance pi = runtimeService.startProcessInstanceByKey("MyReceiveTask", variables); assert (pi!=null); List<Execution> executions = runtimeService.createExecutionQuery().list(); assert (executions.size()==1); Execution execution = runtimeService.createExecutionQuery().singleResult(); runtimeService.setVariable(execution.getId(), "type", "receiveTask"); runtimeService.signal(execution.getId()); executions = runtimeService.createExecutionQuery().list(); assert (executions.size()==1); execution = executions.get(0); runtimeService.setVariable(execution.getId(), "oper", mySpringBean.getName()); runtimeService.signal(execution.getId()); } }
运行程序,结果信息如下所示:
011-3-23 18:21:28 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [activiti-context.xml] 2011-3-23 18:21:29 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [org/shirdrn/workflow/activiti/spring/mySpringContext.xml] ... ... 2011-3-23 18:21:33 org.shirdrn.workflow.activiti.task.CheckBankReceiveTask execute 信息: i am CheckBankReceiveTask. in : {protocol=UM32, repository=10.10.38.99:/home/shirdrn/repository, merchant=Merchant[ICBC], maxTransCount=1000000, in={}, out={}} 2011-3-23 18:21:33 org.shirdrn.workflow.activiti.task.CheckMerchantReceiveTask execute 信息: i am CheckMerchantReceiveTask. in : {protocol=UM32, repository=10.10.38.99:/home/shirdrn/repository, merchant=Merchant[ICBC], maxTransCount=1000000, type=receiveTask, in={}, out={}
评论
3 楼
atgoingguoat
2012-05-28
这个环境需要哪些包?
2 楼
bjyzxxds
2011-10-14
BigBird2012 写道
您好,请问您将Activiti5.6和Spring那个版本整合呢?我现在正和2.5.6版本整合,整合不成功,请问您能指点一下吗?您能把您整合成功的代码发我一份,让我参考一下吗?QQ1755610380
Spring版本3.0.3
1 楼
BigBird2012
2011-10-14
您好,请问您将Activiti5.6和Spring那个版本整合呢?我现在正和2.5.6版本整合,整合不成功,请问您能指点一下吗?您能把您整合成功的代码发我一份,让我参考一下吗?QQ1755610380
发表评论
-
Eclipse,javaw 通过Proxifile代理ipv6协议问题解决
2015-03-17 18:06 2748myeclipse2010升级到myeclipse2014之后 ... -
初始化EHcache CacheManager时报java.net.UnknownHostException
2014-11-13 11:45 12458工程启动时,报一下异常: [wdfportal] [201 ... -
tomcat7可能带来的问题
2013-06-27 00:31 9431、struts标签校验更加严格,如果struts标签中存在嵌 ... -
iBatis执行insert后返回主键
2013-01-18 23:55 1606iBatis插入数据后,返回主键。级联操作很有用。省去了一次的 ... -
Shallow heap & Retained heap
2012-05-16 17:09 49006所有包含Heap Profling功能的工具(MAT, You ... -
什么是两阶段提交协议
2012-05-08 16:58 1024两阶段提交协议 实现分布式事务的关键就是两阶段提交协议。在此 ... -
Abator —— IBatis 代码生成工具
2012-04-03 18:31 18871、在eclipse安装abator插件http://ibat ... -
使用Eclipse远程调试Tomcat
2012-03-23 22:56 1468有些时候,调试不得不用外网,比如说做支付宝的支付接口,服务器后 ... -
Java compiler level does not match the version of the installed Java project fac
2012-03-02 11:32 1274问题现象:项目图标报错“Java compiler level ... -
WebService的事务处理
2012-03-01 15:03 1524如果你只是要解决两个系统之间的事务同步问题,可以采用判断服务是 ... -
线程池(java.util.concurrent.ThreadPoolExecutor)的使用
2012-02-29 15:50 2477一、简介 线程池类为 j ... -
myeclipse 颜色设置(保护视力)
2012-02-28 09:29 20421.window -> Preferences -> ... -
Quartz表达式解析
2012-02-08 14:40 774字段 允许值 允许的特 ... -
使用iBatis中报 java.sql.SQLException: 无效的列类型异常
2011-12-15 14:46 2197<!--Content表 插入应的 ... -
非常有用的proxool属性详细解说
2011-12-13 16:19 1576Proxool连接池是sourceforge下的一个开源项目, ... -
在工程中查找自己修改的所有代码
2011-12-09 17:41 1013在工程中查找自己修改的所有代码的方法: 1.工程右键 -&g ... -
如何在Eclipse中安装和使用ibatis插件Abator
2011-12-01 21:26 49351、获得abator: http://ibatis. ... -
newCachedThreadPool线程池
2011-11-20 11:35 42975public static ExecutorService n ... -
Apache Mina – 简单的客户端/服务端应用示例
2011-11-19 23:49 5477转自http://javasight.net/2011/05/ ... -
Class.forName()、Class.forName().newInstance() 、New 三者区别!
2011-11-15 09:18 1218终于明白为什么加载数据库驱动只用Class.forName() ...
相关推荐
工作流Activiti的学习总结Activiti5.6和Spring3.03整合
Activiti5.6 用户手册
activiti5.6,想对activiti有所提高,进一步了解的朋友必备,对初学者也是必备文档
web.xml 配置
activiti-explorer 与spring整合,可在浏览器进行流程图编辑
赠送jar包:activiti-spring-5.21.0.jar; 赠送原API文档:activiti-spring-5.21.0-javadoc.jar; 赠送源代码:activiti-spring-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-spring-5.21.0.pom; 包含...
activiti-engine-5.6 spring 集成所需要的jar包,现在官网或maven都找不到此版本的jar了。
struts2、sprint3、activiti5整合项目, 其中有很多帮助类,如:时间帮助类,数据库帮助类,string帮助类, excel操作帮助类,jfreechart帮助类,spring帮助类等等, 绝对物超所值!
Activiti与Spring整合开发---Activiti与Spring整合的配置 在Activiti中核心类的是ProcessEngine流程引擎,与Spring整合就是让Spring来... 创建spring与activiti的整合配置文件:activiti-spring.xml(名称不固定);
赠送jar包:activiti-spring-5.21.0.jar; 赠送原API文档:activiti-spring-5.21.0-javadoc.jar; 赠送源代码:activiti-spring-5.21.0-sources.jar; 赠送Maven依赖信息文件:activiti-spring-5.21.0.pom; 包含...
activiti源代码
Alfresco软件在2010年5月17日宣布Activiti业务流程管理(BPM)开源项目的正式启动,其首席架构师由业务流程管理BPM的专家 Tom Baeyens担任。 Activiti项目是一项新的基于Apache许可的开源BPM平台,从基础开始构建,...
Activiti入门篇之二 Spring 与Activiti的入门整合
博文链接:https://gglu.iteye.com/blog/1123912
Activiti5.10整合Spring完成请假流程 Spring+Activiti+Spring Data JPA 流程为:上传流程定义文件+填写请假条(启动工作流)+部门经理审批+人事审批+销假+邮件通知+结束 其中在部门经理和人事审批的时候可以驳回(重新...
亲手实战编写的activiti 5.22与spring mvc的整合手册,主要介绍如何在项目中集成explorer等工作流画图组件
activiti-5.21 + Activiti5.20.0整合spring4.15示例
终于将Activiti的流程设计器分离出来,与SpringMVC,spring整合了起来,先把工程分享出来,等有时间了在慢慢讲解具体的整合步骤。工程下载之后直接可以运行,只需要改一下数据库连接。访问...
activiti和springboot整合只使用application.properties配置文件,解决了jdbc长时间待机连接被收回报错。使用springProcessEngineConfiguration对activiti管理
Activiti5.20.0整合spring4.15示例,整合流程编辑器modeler; 项目导入myeclipse后,请先看doc文件夹下的readme.txt说明文档!