SSH整合JBPM4.4

第一步:导入所需jar包

具体所需jar包见附件图片

第二步:修改jbpm配置文件:

1、src目录下建立jbpm.cfg.xml(注意注释部分)

<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
    <process-engine-context>
        <string name="spring.cfg" value="applicationContext.xml" />
    </process-engine-context>
    <import resource="jbpm.default.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" />
    <import resource="jbpm.businesscalendar.cfg.xml" />
    <import resource="jbpm.console.cfg.xml" />
    <import resource="jbpm.spring.default.cfg.xml"/>
    <!--
    <import resource="jbpm.jobexecutor.cfg.xml" />
    -->
</jbpm-configuration> 

2、src目录下建立jbpm.spring.default.cfg.xml

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

<jbpm-configuration>     

  <process-engine-context>     

    <repository-service />
    <repository-cache />
    <execution-service />
    <history-service />
    <management-service />
    <identity-service />
    <task-service />
<!--
    <hibernate-configuration>
      <cfg resource="jbpm.hibernate.cfg.xml" />
    </hibernate-configuration>     

    <hibernate-session-factory />
-->
    <script-manager default-expression-language="juel"
                    default-script-language="juel"
                    read-contexts="execution, environment, process-engine"
                    write-context="">
      <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
    </script-manager>     

    <authentication />     

    <id-generator />
    <types resource="jbpm.variable.types.xml" />     

    <address-resolver />     

    <business-calendar>
      <monday    hours="9:00-12:00 and 12:30-17:00"/>
      <tuesday   hours="9:00-12:00 and 12:30-17:00"/>
      <wednesday hours="9:00-12:00 and 12:30-17:00"/>
      <thursday  hours="9:00-12:00 and 12:30-17:00"/>
      <friday    hours="9:00-12:00 and 12:30-17:00"/>
      <holiday period="01/07/2008 - 31/08/2008"/>
    </business-calendar>     

    <mail-template name=‘task-notification‘>
      <to users="${task.assignee}"/>
      <subject>${task.name}</subject>
      <text><![CDATA[Hi ${task.assignee},
Task "${task.name}" has been assigned to you.
${task.description}   

Sent by JBoss jBPM
]]></text>
    </mail-template>     

    <mail-template name=‘task-reminder‘>
      <to users="${task.assignee}"/>
      <subject>${task.name}</subject>
      <text><![CDATA[Hey ${task.assignee},
Do not forget about task "${task.name}".
${task.description}   

Sent by JBoss jBPM
]]></text>
    </mail-template>     

  </process-engine-context>     

  <transaction-context>
    <repository-session />
    <db-session />     

    <message-session />
    <timer-session />
    <history-session />
    <mail-session>
      <mail-server>
        <session-properties resource="jbpm.mail.properties" />
      </mail-server>
    </mail-session>
  </transaction-context>     

</jbpm-configuration>    

第三步:修改Spring配置文件

1、applicationContext.xml中加入springHelper配置,作为jbpm processEngine的factory bean

<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
        <property name="jbpmCfg" value="jbpm.cfg.xml" />
    </bean>  

2、applicationContext.xml中加入processEngine配置,并以此为factory bean创建JBPM本身的各种Service

<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="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>  

3、applicationContext.xml的hibernate配置中加入jbpm所需的hbm.xml配置

<property name="mappingLocations">
       <list>
                <value>classpath:jbpm.execution.hbm.xml</value>
                <value>classpath:jbpm.history.hbm.xml</value>
                <value>classpath:jbpm.identity.hbm.xml</value>
                <value>classpath:jbpm.repository.hbm.xml</value>
                <value>classpath:jbpm.task.hbm.xml</value>
       </list>
</property>  

4、完整的applicationContext.xml(包括其余DataSource、SessionFacotry、事务控制等)

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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
    default-lazy-init="true">
    <import resource="serviceContext.xml" />  

    <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
        <property name="jbpmCfg" value="jbpm.cfg.xml" />
    </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="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>  

    <bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
        <property name="jdbcUrl" value="jdbc:oracle:thin:@XXXXX:1521:XE" />
        <property name="username" value="jbpm4" />
        <property name="password" value="jbpm" />
        <property name="idleConnectionTestPeriod" value="60" />
        <property name="idleMaxAge" value="240" />
        <property name="maxConnectionsPerPartition" value="60" />
        <property name="minConnectionsPerPartition" value="20" />
        <property name="partitionCount" value="3" />
        <property name="acquireIncrement" value="10" />
        <property name="preparedStatementCacheSize" value="50" />
        <property name="statementsCachedPerConnection" value="30" />
        <property name="releaseHelperThreads" value="3" />
    </bean>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <property name="targetDataSource">
            <ref local="mainDataSource" />
        </property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="mappingLocations">
            <list>
                <value>classpath:jbpm.execution.hbm.xml</value>
                <value>classpath:jbpm.history.hbm.xml</value>
                <value>classpath:jbpm.identity.hbm.xml</value>
                <value>classpath:jbpm.repository.hbm.xml</value>
                <value>classpath:jbpm.task.hbm.xml</value>
            </list>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.fish119.jssh.pojo.Test</value>
            </list>
        </property>
    </bean>  

    <!-- 事务配置开始 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!--事务配置-->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
        <!-- 配置事务属性 -->
        <property name="transactionAttributes">
            <props>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="delete*">PROPAGATION_REQUIRED</prop>
                <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="*Save*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="exchange*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="set*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="Test*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="*Test">PROPAGATION_REQUIRED,-Exception</prop>
            </props>
        </property>
    </bean>
    <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <list>
                <value>*Service</value>
            </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>
    <!-- 事务配置结束 -->
    <bean id="testDAO" class="com.fish119.jssh.dao.TestDAO" autowire="byType">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
</beans>  

第四步:配置Struts2(使用了convention plugin)

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">  

<struts>
    <constant name="struts.objectFactory" value="spring" />
    <!--
        <constant name="struts.objectFactory.spring.autoWire" value="type"/>
    -->  

    <constant name="struts.devMode" value="true" />
    <constant name="struts.convention.classes.reload" value="true" />  

    <!-- 结果资源所在路径 -->
    <constant name="struts.convention.result.path" value="/" />
    <!-- 默认action所在的包 -->
    <constant name="struts.convention.default.parent.package"
        value="myPackage" />
    <!-- 不被convention组件扫描的包  -->
    <!-- <constant name="struts.convention.exclude.packages" value=""/>  -->  

    <package name="myPackage" extends="json-default">  

        <global-results>
            <result name="exception">/error.jsp</result>
            <result name="error">/error.jsp</result>
            <result name="none">/error.jsp</result>
            <result name="login">/login.jsp</result>
        </global-results>  

        <global-exception-mappings>
            <exception-mapping result="exception" exception="java.lang.Exception">
            </exception-mapping>
        </global-exception-mappings>  

    </package>
</struts>  

第五步:测试

1、建立action类:IndexAction

public class IndexAction extends BaseAction{   

    private static final long serialVersionUID = 1L;   

    ProcessEngine processEngine;
    RepositoryService repositoryService;
    ExecutionService executionService;
    TaskService taskService;
    HistoryService historyService;
    IdentityService identityService;   

    public ProcessEngine getProcessEngine(){
        return processEngine;
    }   

    public void setProcessEngine(ProcessEngine processEngine){
        this.processEngine = processEngine;
    }   

    public RepositoryService getRepositoryService(){
        return repositoryService;
    }   

    public void setRepositoryService(RepositoryService repositoryService){
        this.repositoryService = repositoryService;
    }   

    public ExecutionService getExecutionService(){
        return executionService;
    }   

    public void setExecutionService(ExecutionService executionService){
        this.executionService = executionService;
    }   

    public TaskService getTaskService(){
        return taskService;
    }   

    public void setTaskService(TaskService taskService){
        this.taskService = taskService;
    }   

    public HistoryService getHistoryService(){
        return historyService;
    }   

    public void setHistoryService(HistoryService historyService){
        this.historyService = historyService;
    }   

    public IdentityService getIdentityService(){
        return identityService;
    }   

    public void setIdentityService(IdentityService identityService){
        this.identityService = identityService;
    }   

    public String execute(){
            System.out.println("processEngine:" + this.getProcessEngine());
            System.out.println("repositoryService:"
                    + this.getRepositoryService());
            System.out
                    .println("executionServcie:" + this.getExecutionService());
            System.out.println("taskService:" + this.getTaskService());
            System.out.println("historyService:" + this.getHistoryService());
        return SUCCESS;
    }
}  

2、启动tomcat,访问http://localhost:8080/ProjectName/index。

本文转自:http://blog.csdn.net/yjboy1982/article/details/6043379

时间: 2024-11-08 20:24:53

SSH整合JBPM4.4的相关文章

JBPM4.4+SSH 整合配置及完整实例

整合jBPM4.4+ssh过程(spring接管struts2和hibernate,例中都整合在application.xml中,没有单独的jbpm.hibernate.cfg.xml): 1.在sessionFactory的mappingLocations属性加入以下几个jbpm.*.hbm.xml由jBPM自带 <value>classpath:jbpm.repository.hbm.xml</value> <value>classpath:jbpm.executi

SSH整合基础

1.Spring整合Hibernate 整合步骤 导包 配置appliactionContext.xml 创建实体类和映射关系文件 创建DAO接口及实现类 声明DAO组件,注入SessionFactory 2.Spring整合Struts2 导包 配置web.xml 配置applicationContext.xml,开启注解扫描 创建并声明Action 配置Action 创建JSP 3.整合的基本原理 Struts原本使用StrutsObjectFactory来读取struts.xml,根据ac

SSH整合开发时Scope为默认时现象与原理

1.前提知识 1)scope默认值 进行SSH整合开发时,Struts2的action需要用spring容器进行管理,只要涉及到类以bean的形式入到spring容器中,不管是xml配置还是使用注解方式进行配置,都会涉及到spring管理bean的scope,其一共有五种取值,而其默认值为singleton,也就是单例模型,所有对此bean引用为同一个对象. 2)action应为多例 struts2作为MVC中视图(View)层框架,其最主要任务就是接收用户请求,然后调用业务逻辑层进行处理,这种

Spring(八)SSH整合简述

一.Spring与Struts2的整合 1.1.整合步骤 1.2.配置web.xml 1.3.配置spring配置文件applicationContext.xml 1.4.配置struts配置文件 1.5.Action继承ActionSupport类 二.spring与hibernate整合 2.1.步骤 2.2.注入sessionFactory <--数据源--> <bean id="dataSource" class="org.springframewo

SSH整合(配置方式)

工程目录: /SSH1/src/cn/itcast/domain/Book.java package cn.itcast.domain; /** * 图书 */ public class Book { private Integer id; // 图书编号 private String name; // 图书名称 private Double price; // 图书价格 public Integer getId() { return id; } public void setId(Intege

mysql+ssh整合例子,附源码下载

项目引用jar下载:http://download.csdn.net/detail/adam_zs/7262727 项目源码下载地址:http://download.csdn.net/detail/adam_zs/7262749 今天花时间把ssh整合了一下,重新再学习一下,希望对大家有所帮助! 我用的是mysql数据库,建表语句比较简单就不贴出来了,建表的时候记的设置id为自动增加哦. 项目文件位置,项目引用jar包 项目配置文件 web.xml <?xml version="1.0&q

SSH整合(1)异常

信息: No Spring WebApplicationInitializer types detected on classpath 十二月 01, 2016 10:06:12 下午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.spr

Java框架----SSH整合回顾

1,新建工程,类型为Web Project,设置默认编码为UTF-8,并创建如下文件夹 1,Source Folder 1,src 项目源码 2,config 配置文件 3,test 单元测试 2,普通文件夹 1,WebRoot/style css与图片等文件 2,WebRoot/script js脚本文件 3,WebRoot/WEB-INF/jsp jsp页面文件 3,包结构 1,实体 cn.itcast.oa.domain 2,Dao cn.itcast.oa.dao Dao接口 cn.it

ssh整合例子

今天给大家介绍一下最新版本的SSH(struts2.2.1+ hibernate3.6+spring3.0.5)组合.注意本讲解为手工搭建! 一.为SSH做好准备 struts2-2.2.1-all.zip       hibernate-distribution-3.6.0.Final-dist.zip spring-framework-3.0.5.RELEASE.zip spring-framework-2.5.6-with-dependencies.zip slf4j-1.6.1.zip