jbpm4.4 和spring整合起来 .
流程文件如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <process name="leave" xmlns="http://jbpm.org/4.4/jpdl">
- <start g="196,25,48,48" name="start1">
- <transition to="申请"/>
- </start>
- <task assignee="#{owner}" form="leave.htm?method=toFillForm" g="172,118,92,52" name="申请">
- <transition to="managerAudit"/>
- </task>
- <task assignee="yexs" form="leave.htm?method=toManageAudit" g="175,217,92,52" name="managerAudit">
- <transition g="-32,-8" name="批准" to="exclusive1"/>
- <transition g="128,221;124,165:-42,-18" name="驳回" to="申请"/>
- </task>
- <decision expr="#{day > 3 ? '老板审批' : '结束'}" g="200,308,48,48" name="exclusive1">
- <transition g="-39,-10" name="结束" to="end1"/>
- <transition g="339,342:-71,-17" name="老板审批" to="老板审批"/>
- </decision>
- <task assignee="laoxin" form="leave.htm?method=toBossAudit" g="294,375,92,52" name="老板审批">
- <transition g="339,457:" to="end1"/>
- </task>
- <end g="199,445,48,48" name="end1"/>
- </process>
<?xml version="1.0" encoding="UTF-8"?>
<process name="leave" xmlns="http://jbpm.org/4.4/jpdl">
<start g="196,25,48,48" name="start1">
<transition to="申请"/>
</start>
<task assignee="#{owner}" form="leave.htm?method=toFillForm" g="172,118,92,52" name="申请">
<transition to="managerAudit"/>
</task>
<task assignee="yexs" form="leave.htm?method=toManageAudit" g="175,217,92,52" name="managerAudit">
<transition g="-32,-8" name="批准" to="exclusive1"/>
<transition g="128,221;124,165:-42,-18" name="驳回" to="申请"/>
</task>
<decision expr="#{day > 3 ? '老板审批' : '结束'}" g="200,308,48,48" name="exclusive1">
<transition g="-39,-10" name="结束" to="end1"/>
<transition g="339,342:-71,-17" name="老板审批" to="老板审批"/>
</decision>
<task assignee="laoxin" form="leave.htm?method=toBossAudit" g="294,375,92,52" name="老板审批">
<transition g="339,457:" to="end1"/>
</task>
<end g="199,445,48,48" name="end1"/>
</process>
jbpm.cfg.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <jbpm-configuration>
- <import resource="jbpm.default.cfg.xml" />
- <import resource="jbpm.businesscalendar.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" />
- <!-- 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>
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.businesscalendar.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" />
<!-- 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>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- Jbpm 服务 -->
<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" >
<property name="jbpmCfg" value="jbpm/jbpm.cfg.xml"></property>
</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="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<!-- 装载spring提供的分发组件 -->
<bean id="paraMethodResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName" value="method" />
<property name="defaultMethodName" value="list" />
</bean>
<!-- 上传文件 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>4000000000</value>
</property>
<property name="maxInMemorySize">
<value>10000000</value>
</property>
<property name="defaultEncoding">
<value>utf-8</value>
</property>
<property name="uploadTempDir">
<value>/temp</value>
</property>
</bean>
<!-- 装载velocity配置文件 -->
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>/</value>
</property>
<property name="configLocation">
<value>/WEB-INF/classes/velocity.properties</value>
</property>
</bean>
<!-- 装载spring提供的velocity组建 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="requestContextAttribute" value="rc"/>
<property name="exposeSessionAttributes" value="true" />
<property name="suffix" value=".html"></property>
<property name="dateToolAttribute">
<value>dateTool</value>
</property>
<property name="toolboxConfigLocation"><value>/WEB-INF/velocity-toolbox.xml</value> </property>
</bean>
<!-- 接口映射 配置URL请求 -->
<bean id="simpleUrlMapping"
class="com.yb.hrm.baselink.util.UrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor" />
</list>
</property>
</bean>
<!-- business 服务 -->
<bean id="baseBusiness"
class="com.yb.hrm.baselink.business.BaseBusiness" />
<!-- Service 服务 -->
<bean id="baseService"
class="com.yb.hrm.baselink.service.BaseService" />
<!-- DAO申明 -->
<bean id="baseDAO" class="com.yb.hrm.baselink.dao.BaseDAOImp">
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 在开发的时候可以这样定义,但部署的时候一定要详细定义 -->
<tx:method name="*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED"
rollback-for="-Exception" read-only="true" />
<tx:method name="test*" propagation="REQUIRED"
rollback-for="-Exception" read-only="true" />
<tx:method name="find*" propagation="REQUIRED"
rollback-for="-Exception" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"
rollback-for="-Exception" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="-Exception" />
<tx:method name="batch*" propagation="REQUIRED"
rollback-for="-Exception" />
<tx:method name="modify*" propagation="REQUIRED"
rollback-for="-Exception" />
<tx:method name="delete*" propagation="REQUIRED"
rollback-for="-Exception" />
</tx:attributes>
</tx:advice>
<!-- 配置哪些类哪些方法使用事务-->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution(* com.yb.hrm..*.*Business.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="allManagerMethod" />
</aop:config>.....
business 的代码:
- public class LeaveBusiness extends BaseBusiness {
- private RepositoryService repositoryService;
- private ExecutionService executionService;
- private TaskService taskService;
- public void setTaskService(TaskService taskService) {
- this.taskService = taskService;
- }
- public void setRepositoryService(RepositoryService repositoryService) {
- this.repositoryService = repositoryService;
- }
- public void setExecutionService(ExecutionService executionService) {
- this.executionService = executionService;
- }
-
-
- public void deploy(){
- ZipInputStream zis = new ZipInputStream(this.getClass()
- .getResourceAsStream("/com/yb/hrm/jbpm/leave/jpdl/leave.zip"));
- repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();
- }
-
-
-
- public void removeDeploy(String deployId){
- repositoryService.deleteDeploymentCascade(deployId);
- }
-
-
-
- public void startDefine(String deployId,String loginName){
- Map map = new HashMap();
- map.put("owner", loginName);
- executionService.startProcessInstanceByKey("leave", map);
- }
-
-
-
- public List getDefinition(){
- return repositoryService.createProcessDefinitionQuery().list();
- }
-
-
-
- public ProcessDefinition getDefinitionByPiId(String id){
- return repositoryService.createProcessDefinitionQuery().processDefinitionId(id).uniqueResult();
- }
-
-
-
- public List getInstance(){
- return executionService.createProcessInstanceQuery().list();
- }
-
-
-
- public ProcessInstance getInstanceById(String id){
- return executionService.findProcessInstanceById(id);
- }
-
-
-
-
- public List getTaskByUserId(String loginName){
- return taskService.findPersonalTasks(loginName);
- }
-
-
-
-
- public ActivityCoordinates getAc(ProcessInstance pi){
- return repositoryService.getActivityCoordinates(pi.getProcessDefinitionId(),pi.findActiveActivityNames().iterator().next());
- }
-
-
-
-
- public InputStream getPicStream(ProcessDefinition pd){
- return repositoryService.getResourceAsStream(pd.getDeploymentId(), "leave.png");
- }
-
-
-
-
- public void submitForm(Map map,String taskId){
- taskService.completeTask(taskId, map);
- }