黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

jBPM4與Spring的集成

系統(tǒng) 2283 0

?現(xiàn)在流行抱大腿,不過對(duì)眼光的要求也頗高。要不就如高也,即使四眼,一樣無用。對(duì)Java企業(yè)開發(fā)而言,Spring的腿則是一定要抱的。而所謂抱Spring的腿,無外乎三點(diǎn):

?

一是通過Spring暴露出服務(wù),將服務(wù)配置到Spring的IOC容器里;

二是在自己的運(yùn)行環(huán)境里訪問到Spring的IOC容器,能夠輕松使用Spring容器里所配置的服務(wù);

三是對(duì)于具有事務(wù)管理特性的項(xiàng)目來說,將事務(wù)管理與Spring的事務(wù)管理進(jìn)行合并。


????? 下面分別討論:

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

Java代碼 復(fù)制代碼
  1. ProcessEngine?processEngine?=? new ?Configuration() ??
  2. ??????.buildProcessEngine();??
      ProcessEngine processEngine = new Configuration()
      .buildProcessEngine();
    

?

?

Java代碼 復(fù)制代碼
  1. RepositoryService?repositoryService?=?processEngine.getRepositoryService(); ??
  2. ExecutionService?executionService?=?processEngine.getExecutionService(); ??
  3. TaskService?taskService?=?processEngine.getTaskService(); ??
  4. HistoryService?historyService?=?processEngine.getHistoryService(); ??
  5. ManagementService?managementService?=?processEngine.getManagementService();??
      RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
    

?



通過Spring暴露這些服務(wù),配置如下:

Xml代碼 復(fù)制代碼
  1. < bean ? id = "jbpmConfiguration" ? class = "org.jbpm.pvm.internal.cfg.SpringConfiguration" > ??
  2. ???????? < constructor-arg ? value = "be/inze/spring/demo/jbpm.cfg.xml" ? /> ??
  3. ???? </ bean > ??
  4. ??? ??
  5. ???? < bean ? id = "processEngine" ? factory-bean = "jbpmConfiguration" ? factory-method = "buildProcessEngine" ? /> ??
  6. ???? < bean ? id = "repositoryService" ? factory-bean = "processEngine" ? factory-method = "getRepositoryService" ? /> ??
  7. ???? < bean ? id = "executionService" ? factory-bean = "processEngine" ? factory-method = "getExecutionService" ? /> ??
      <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" />
    

?



細(xì)心的你會(huì)發(fā)現(xiàn),配置時(shí)使用了JbpmConfiguration 的子類SpringConfiguration。SpringConfiguration相比JbpmConfiguration有哪些增強(qiáng)呢,下面再講。總之,現(xiàn)在,就可以使用Spring來獲取或注入這些Jbpm4所提供的服務(wù)了。

二、在environment里加入SpringContext
jBPM4的environment(運(yùn)行期環(huán)境)提供Engine IOC(process-engine-context)和Transaction IOC(transaction-context)。要想在運(yùn)行期方便地訪問到Spring里所配置的服務(wù),最直接的方法就是在environment里加入Spring IOC(applicationContext)的引用。


SpringConfiguration即是對(duì)JbpmConfiguration增強(qiáng)了對(duì)Spring IOC的一個(gè)引用。
?

?
SpringConfiguration是如何做到的呢?簡單,實(shí)現(xiàn)Spring的ApplicationContextAware接口,自動(dòng)持有applicationContext,然后openEnvironment時(shí)將其加入environment。

Java代碼 復(fù)制代碼
  1. environment.setContext( new ?SpringContext(applicationContext));??
      environment.setContext(new SpringContext(applicationContext));
    

?


SpringContext是對(duì)applicationContext的簡單封裝。

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

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

Xml代碼 復(fù)制代碼
  1. < hibernate-configuration > ??
  2. ?? < cfg ? resource = "jbpm.hibernate.cfg.xml" ? /> ???? ??
  3. </ hibernate-configuration > ??
  4. ??
  5. < hibernate-session-factory ? /> ??
          <hibernate-configuration>
      <cfg resource="jbpm.hibernate.cfg.xml" />    
    </hibernate-configuration>

    <hibernate-session-factory />
    

?


相關(guān)配置挪動(dòng)至Spring配置文件。

三、??? 事務(wù)

哪里有數(shù)據(jù)庫操作,哪里就有事務(wù)。對(duì)于嵌入式工作流而言,最重要的集成就是事務(wù)的集成。這里先分析jBPM4的事務(wù)實(shí)現(xiàn),然后再介紹集成入Spring的事務(wù)實(shí)現(xiàn)。

1、??? Command模式
jBPM4的邏輯實(shí)現(xiàn)采用了Command模式。
?

?
采用Command模式后,jBPM4對(duì)CommandService構(gòu)造攔截器(Interceptor)鏈,配置在jbpm.cfg.xml的process-engine-context里:

Xml代碼 復(fù)制代碼
  1. < command-service > ??
  2. ?????? < retry-interceptor ? /> ??
  3. ?????? < environment-interceptor ? /> ??
  4. ?????? < standard-transaction-interceptor ? /> ??
  5. ???? </ command-service > ??
      <command-service>
      <retry-interceptor />
      <environment-interceptor />
      <standard-transaction-interceptor />
    </command-service>
    

?


2、??? 原有的事務(wù)實(shí)現(xiàn)

jBPM4原有的事務(wù)通過StandardTransactionInterceptor實(shí)現(xiàn),在CommandService執(zhí)行Command之前打開事務(wù)(實(shí)際委派Hibernate的事務(wù)管理),完成后提交/回滾。
?

?

jBPM4的事務(wù)是基于Command的。

3、??? 集成入Spring的事務(wù)實(shí)現(xiàn)
Spring的事務(wù)是基于服務(wù)調(diào)用的。
?

?

使jBPM4使用Spring提供的事務(wù):

Xml代碼 復(fù)制代碼
  1. < command-service > ??
  2. ?????? < retry-interceptor ? /> ??
  3. ?????? < environment-interceptor ? /> ??
  4. ?????? < spring-transaction-interceptor ? current = "true" ? /> ??
  5. </ command-service > ??
      <command-service>
      <retry-interceptor />
      <environment-interceptor />
      <spring-transaction-interceptor current="true" />
</command-service>
    

?



攔截器換用 SpringTransactionInterceptor ,SpringTransactionInterceptor從environment 提供的Spring IOC獲取PlatformTransactionManager,使用事務(wù)模板回調(diào)Command,事務(wù)傳播模式強(qiáng)制加入當(dāng)前事務(wù)。

同時(shí),對(duì)hibernate session的配置(jbpm.cfg.xml的transaction-context)強(qiáng)制從當(dāng)前線程中獲取:

Xml代碼 復(fù)制代碼
  1. < hibernate-session ? current = "true" /> ??
      <hibernate-session current="true"/>
    

?


并干掉原有的事務(wù)實(shí)現(xiàn):

Xml代碼 復(fù)制代碼
  1. < transaction ? /> ??
      <transaction />
    

?


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

?jbpm4GA發(fā)布已有一個(gè)月了,作為jbpm的新手,發(fā)現(xiàn)關(guān)于jbpm4的資源太稀少了,本人把jbpm4與spring的整合過程發(fā)布一下。本人使用struts2+hibernate+spring整合環(huán)境。
??? 首先復(fù)制官方下載的壓縮包中jbpm.jar到項(xiàng)目中,并根據(jù)腳本創(chuàng)建數(shù)據(jù)庫表。
???? 其次在spring的配置文件applicationContext.xml中的sessionFactory中加入
??? <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
??? <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">??
???? <constructor-arg value="jbpm.cfg.xml" />
??? </bean>??
??? <bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
??? 把從官方下載的壓縮包里的jbpm.hibernate.cfg.xml、jbpm.cfg.xml、jbpm.mail.templates.examples.xml3個(gè)xml文件放入src中。
???? 然后再修改jbpm.hibernate.cfg.xml文件中的數(shù)據(jù)庫連接信息。
??? 其次strtus2的action文件中添加private SpringConfiguration jbpmConfiguration;并設(shè)定其get、set方法。
??? 在處理方法中添加:
???? ProcessEngine processEngine = jbpmConfiguration.buildProcessEngine();
??? RepositoryService repositoryService = processEngine.getRepositoryService();
??? String deploymentId = repositoryService.createDeployment()
?????? .addResourceFromClasspath("****.jpdl.xml").deploy();
??? repositoryService.deleteDeployment(deploymentId);
??? 這里的****是需要發(fā)布的jbpm流程文件名。

jBPM4與Spring的集成


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論