<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Vanlin Study Club

    Java Js Flex

    jBPM4與Spring的集成[轉載]

           現在流行抱大腿,不過對眼光的要求也高。要不就如高也,即使四眼,一樣無用。對Java企業開發而言,Spring的腿則是一定要抱的。而所謂抱Spring的腿,無外乎三點:

    一是通過Spring暴露出服務,將服務配置到Spring的IOC容器里;
    二是在自己的運行環境里訪問到Spring的IOC容器,能夠輕松使用Spring容器里所配置的服務;
    三是對于具有事務管理特性的項目來說,將事務管理與Spring的事務管理進行合并。

            下面分別討論:

    一、    通過Spring暴露服務
    還記得在jBPM4的運行期環境里提到的JbpmConfiguration嗎?它是整個jBPM4的入口,并且是整個應用獨此一份的。通過它可以獲取processEngine,并藉此獲得工作流引擎所提供的各種服務:

    ProcessEngine processEngine 
    = new Configuration()
          .buildProcessEngine();


    RepositoryService repositoryService 
    = processEngine.getRepositoryService();
    ExecutionService executionService 
    = processEngine.getExecutionService();
    TaskService taskService 
    = processEngine.getTaskService();
    HistoryService historyService 
    = processEngine.getHistoryService();
    ManagementService managementService 
    = processEngine.getManagementService();

    通過Spring暴露這些服務,配置如下:
    <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
            
    <constructor-arg value="be/inze/spring/demo/jbpm.cfg.xml" />
        
    </bean>
       
        
    <bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
        
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
        
    <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />


    細心的你會發現,配置時使用了JbpmConfiguration 的子類SpringConfiguration。SpringConfiguration相比JbpmConfiguration有哪些增強呢,下面再講。總之,現在,就可以使用Spring來獲取或注入這些Jbpm4所提供的服務了。

    二、在environment里加入SpringContext
    jBPM4的environment(運行期環境)提供Engine IOC(process-engine-context)和Transaction IOC(transaction-context)。要想在運行期方便地訪問到Spring里所配置的服務,最直接的方法就是在environment里加入Spring IOC(applicationContext)的引用。
    SpringConfiguration即是對JbpmConfiguration增強了對Spring IOC的一個引用。
     
    SpringConfiguration是如何做到的呢?簡單,實現Spring的ApplicationContextAware接口,自動持有applicationContext,然后openEnvironment時將其加入environment。

    environment.setContext(new SpringContext(applicationContext));


    SpringContext是對applicationContext的簡單封裝。

    那么什么從Engine IOC移民到Spring IOC了呢?是的,最重要的就是Hibernate Session Factory。

    在jbpm.cfg.xml的process-engine-context里干掉:

        <hibernate-configuration>
          
    <cfg resource="jbpm.hibernate.cfg.xml" />    
        
    </hibernate-configuration>

        
    <hibernate-session-factory />

      
    相關配置挪動至Spring配置文件。

    三、    事務
    哪里有數據庫操作,哪里就有事務。對于嵌入式工作流而言,最重要的集成就是事務的集成。這里先分析jBPM4的事務實現,然后再介紹集成入Spring的事務實現。

    1、    Command模式
    jBPM4的邏輯實現采用了Command模式。
     
    采用Command模式后,jBPM4對CommandService構造攔截器(Interceptor)鏈,配置在jbpm.cfg.xml的process-engine-context里:
    <command-service>
          
    <retry-interceptor />
          
    <environment-interceptor />
          
    <standard-transaction-interceptor />
        
    </command-service>


    2、    原有的事務實現
    jBPM4原有的事務通過StandardTransactionInterceptor實現,在CommandService執行Command之前打開事務(實際委派Hibernate的事務管理),完成后提交/回滾。
     
    jBPM4的事務是基于Command的。

    3、    集成入Spring的事務實現
    Spring的事務是基于服務調用的。

    使jBPM4使用Spring提供的事務:
    <command-service>
          
    <retry-interceptor />
          
    <environment-interceptor />
          
    <spring-transaction-interceptor current="true" />
    </command-service>


    攔截器換用SpringTransactionInterceptor,SpringTransactionInterceptor從environment 提供的Spring IOC獲取PlatformTransactionManager,使用事務模板回調Command,事務傳播模式強制加入當前事務。

    同時,對hibernate session的配置(jbpm.cfg.xml的transaction-context)強制從當前線程中獲取:
    <hibernate-session current="true"/>

    并干掉原有的事務實現:
    <transaction />

    參考文檔:
    http://www.slideshare.net/guest8d4bce/spring-integration-with-jbpm4




    http://www.tkk7.com/ronghao 榮浩原創

    posted on 2009-10-11 10:09 vanlin 閱讀(233) 評論(0)  編輯  收藏 所屬分類: jbpm

    主站蜘蛛池模板: 亚洲国产日韩一区高清在线| 国产乱辈通伦影片在线播放亚洲| 亚洲国产精品久久久久网站 | 成年在线观看网站免费| 亚洲综合一区二区精品久久| 无码午夜成人1000部免费视频| 国产亚洲精品xxx| 18禁美女裸体免费网站| 亚洲一卡2卡3卡4卡国产网站 | 免费在线观看一区| 亚洲精品无码激情AV| 中文字幕免费在线播放| 亚洲成a人片77777老司机| 最近中文字幕免费mv在线视频| 亚洲乱码在线视频| 成人毛片免费网站| 手机永久免费的AV在线电影网| 在线A亚洲老鸭窝天堂| 久久久久国产精品免费看| 亚洲成人午夜电影| 国产免费人人看大香伊| 成在人线av无码免费高潮喷水 | 亚洲欧美成人综合久久久| 免费a级黄色毛片| 免费无码黄网站在线看| 亚洲午夜电影一区二区三区| 国产精品公开免费视频| 成人精品视频99在线观看免费| 久久久久亚洲av无码专区| 国产成人免费全部网站| 成人A毛片免费观看网站| 亚洲日韩中文字幕| 亚洲国模精品一区| 最近中文字幕完整版免费高清| 亚洲熟女综合一区二区三区| 国产精品亚洲精品日韩已方| 久草视频免费在线| 国产黄色片免费看| 亚洲永久在线观看| 国产亚洲av片在线观看播放 | 好男人www免费高清视频在线|