Spring3集成jbpm4.4

1、Spring配置文件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:context="http://www.springframework.org/schema/context"
       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-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
          
 <context:annotation-config/>
 <context:component-scan base-package="com.cqs"/>
 <aop:aspectj-autoproxy />
 
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"/>
    <property name="user" value="root"/>
    <property name="password" value="cqsztt"/>
    <property name="initialPoolSize" value="3" />
    <property name="minPoolSize" value="3" />
    <property name="maxPoolSize" value="50" />
    <property name="maxIdleTime" value="600" />
    <property name="maxStatements" value="100" />
    <property name="acquireIncrement" value="3" />

  </bean>
  <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />//如果jbpm的主配置文件名是不是jbpm.cfg.xml话,需要增加以下两行,SpringHelper源代码里面可以看出来,jbpm默认的配置文件名就是jbpm.cfg.xml

   <!--

        <property name="jbpmCfg">

               <value>jbpm.cfg.xml</value>

        </property>

   -->

  <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
  <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan">
     <list>
      <value>com.cqs.entity</value>
     </list>
    </property>
    <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">org.hibernate.dialect.MySQLInnoDBDialect</prop> <!--不要使用MySQLDialect,会出莫名其妙的错误-->
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.format_sql">true</prop> 
          <prop key="hibernate.hbm2ddl.auto">update</prop> 
   </props>

    </property>
  </bean>
 
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
  </bean>
 
  <!--<tx:annotation-driven transaction-manager="transactionManager"/>-->
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
   <tx:attributes>
    <tx:method name="save" propagation="REQUIRED"/>
    <tx:method name="update" propagation="REQUIRED"/>
    <tx:method name="is*" read-only="true"/>
   </tx:attributes>
  </tx:advice>
  <aop:config>
   <aop:pointcut expression="execution(public * com.cqs.service.impl.*.*(..))" id="userServicePointcut"/>
   <aop:advisor advice-ref="txAdvice" pointcut-ref="userServicePointcut"/>
  </aop:config>
 
  <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
   <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
 
</beans>

 

2、jbpm.cfg.xml配置文件修改如下:

 

<?xml version="1.0" encoding="UTF-8"?>

<jbpm-configuration>

  <import resource="jbpm.customer.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>
3、测试类代码:

package com.cqs.springTest;

import javax.annotation.Resource;

import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.IdentityService;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;


@ContextConfiguration("classpath:applicationContext.xml")
public class TestSendMail extends AbstractJUnit4SpringContextTests{
 
 @Resource RepositoryService repositoryService;
 
 @Resource ExecutionService executionService;
 
 @Resource TaskService  taskService;
 
 @Resource HistoryService historyService;
 
 @Resource IdentityService identityService;
 
 @Test
 public void testSendMail() {
  String deployId = repositoryService.createDeployment()
  .addResourceFromClasspath("send_mail.jpdl.xml").deploy();

 

  executionService.startProcessInstanceByKey("send_mail");
  
  repositoryService.deleteDeploymentCascade(deployId);
 }

}

 

4、send_mail.jpdl.xml内容:

<?xml version="1.0" encoding="UTF-8"?>

<process name="send_mail" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="221,113,48,48" name="start">
      <transition name="to send mail" to="send mail" g="-77,-17"/>
   </start>
   <mail g="213,216,92,52" name="send mail">
 
      <from addresses="cuitsingsh@163.com"/>
      <to addresses="cuitsingsh@163.com, kingcqs@sina.com"/>
      <subject>test Spring  jbpm4.4 mail</subject>
      <text> hello! Success !</text>
 
      <transition name="to end" to="end" g="-41,-17"/>
   </mail>
   <end g="239,362,48,48" name="end"/>
  
</process>

这是个发送Email的简单工作流,jbmp4.4配置Mail的相关方法在我的另一篇文章有介绍

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值