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

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

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

    網(wǎng)路冷眼@BlogJava

    熙熙攘攘一閑人 以冷靜的眼光觀察技術(shù)
    posts - 88, comments - 193, trackbacks - 0, articles - 28
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    Chapter 4. Spring integration(Spring集成)

    Table of Contents

    ProcessEngineFactoryBean
    Transactions(事務(wù))
    Expressions(表達(dá)式)
    Automatic resource deployment(自動(dòng)資源部署)
    Unit testing(單元測(cè)試)

    While you definitely can use Activiti without Spring, we've provided some very nice integration features that are explained in this chapter.

    盡管你肯定能夠不用使用Spring而使用Activiti,但是本章將解釋一些優(yōu)秀的Spring集成特性。

    ProcessEngineFactoryBean

    The ProcessEngine can be configured as a regular Spring bean. The starting point of the integration is the class org.activiti.spring.ProcessEngineFactoryBean. That bean takes a process engine configuration and creates the process engine. This means that the way and all configuration properties documented in the configuration section are exactly the same as for Spring:

    ProcessEngine能夠配置為一個(gè)普通的Spring bean。集成的開(kāi)始點(diǎn)是類(lèi)org.activiti.spring.ProcessEngineFactoryBean。那個(gè)bean提取一個(gè)流程并建立流程引擎。這意味著方法和所有在配置部分的歸檔的配置屬性,完全和Spring相同:

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    ...
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    

    Do note that the processEngineConfiguration bean now uses the org.activiti.spring.SpringProcessEngineConfiguration class.

    一定要注意:processEngineConfiguration bean現(xiàn)在使用org.activiti.spring.SpringProcessEngineConfiguration 類(lèi)。

    Transactions(事務(wù))

    We'll explain the SpringTransactionIntegrationTest found in the spring examples of the distribution step by step. Here is the spring configuration file that we use in this example (located in SpringTransactionIntegrationTest-context.xml). The quoted section contains the dataSource, transactionManager, processEngine and the Activiti Engine services.

    我們將一步一步地解釋在發(fā)行包中的Spring示例的SpringTransactionIntegrationTest 。這里是這個(gè)示例里所使用的配置文件(位置在SpringTransactionIntegrationTest-context.xml)。引號(hào)部分包含了數(shù)據(jù)源,事務(wù)管理器,流程引擎和Activiti引擎服務(wù)。

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    <bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
    <property name="targetDataSource">
    <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    <property name="driverClass" value="org.h2.Driver" />
    <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
    <property name="username" value="sa" />
    <property name="password" value="" />
    </bean>
    </property>
    </bean>
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="databaseType" value="h2" />
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    <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" />
    ...

    The remainder of that spring configuration file contains the beans and configuration that we'll use in this particular example:

    Spring配置文件的其余部分包含了bean和在這個(gè)示例所使用的配置:

    <beans>
    ...
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="userBean" class="org.activiti.spring.test.UserBean">
    <property name="runtimeService" ref="runtimeService" />
    </bean>
    <bean id="printer" class="org.activiti.spring.test.Printer" />
    </beans>

    First the application context is created with any of the Spring ways to do that. In this example you could use a classpath XML resource to configure our Spring application context:

    首先,用任何Spring方式建立應(yīng)用程序上下文。在本例,能夠使用一個(gè)classpath XML 資源來(lái)配置我們的Spring應(yīng)用程序上下文:

    ClassPathXmlApplicationContext applicationContext =
    new ClassPathXmlApplicationContext("org/activiti/examples/spring/SpringTransactionIntegrationTest-context.xml");

    or since it is a test:

    或者它是一個(gè)測(cè)試:

    @ContextConfiguration("classpath:org/activiti/spring/test/transaction/SpringTransactionIntegrationTest-context.xml")

    Then we can get the service beans and invoke methods on them. The ProcessEngineFactoryBean will have added an extra interceptor to the services that applies Propagation.REQUIRED transaction semantics on the Activiti service methods. So we can use for example the repositoryService to deploy a process like this:

    然后我們能夠得到服務(wù)bean并調(diào)用它們之上的方法。將對(duì)一個(gè)應(yīng)用繁殖的,在Activiti服務(wù)方法之上必要的事務(wù)語(yǔ)義服務(wù)增加一個(gè)額外的攔截器。所以我們能夠像下面來(lái)部署一個(gè)流程來(lái)使用 repositoryService:

    RepositoryService repositoryService = (RepositoryService) applicationContext.getBean("repositoryService");
    String deploymentId = repositoryService
    .createDeployment()
    .addClasspathResource("org/activiti/spring/test/hello.bpmn20.xml")
    .deploy()
    .getId();
    

    The other way around also works. In this case, the Spring transaction will be around the userBean.hello() method and the Activiti service method invocation will join that same transaction.

    其它方法也可工作。在這種情況下, Spring事務(wù)將包圍在方法附近。Activiti服務(wù)方法調(diào)用將加入同一事務(wù)。

    UserBean userBean = (UserBean) applicationContext.getBean("userBean");
    userBean.hello();

    The UserBean looks like this. Remember from above in the Spring bean configuration we injected the repositoryService into the userBean.

    UserBean看起來(lái)如此。記得嗎,在上面的Spring bean配置里,已將repositoryService注入到userBean。

    public class UserBean {
    /** injected by Spring */
    private RuntimeService runtimeService;
    @Transactional
    public void hello() {
    // here you can do transactional stuff in your domain model
    // and it will be combined in the same transaction as
    // the startProcessInstanceByKey to the Activiti RuntimeService
    runtimeService.startProcessInstanceByKey("helloProcess");
    }
    public void setRuntimeService(RuntimeService runtimeService) {
    this.runtimeService = runtimeService;
    }
    }

    Expressions(表達(dá)式)

    When using the ProcessEngineFactoryBean, by default, all expressions in the BPMN processes will also 'see' the Spring beans. For example, the SpringTransactionIntegrationTest hello.bpmn20.xml shows how a method on a Spring bean can be invoked using a UEL method expression:

    當(dāng)使用ProcessEngineFactoryBean時(shí), 缺省地,在BPMN流程的所有表達(dá)式也將看見(jiàn)Spring beans。例如,SpringTransactionIntegrationTest hello.bpmn20.xml展示了如何能用一個(gè)UEL方法表達(dá)式調(diào)用 在Spring bean上一個(gè)方法。

    <definitions id="definitions" ...>
    <process id="helloProcess">
    <startEvent id="start" />
    <sequenceFlow id="flow1" sourceRef="start" targetRef="print" />
    <serviceTask id="print" activiti:expression="#{printer.printMessage()}" />
    <sequenceFlow id="flow2" sourceRef="print" targetRef="end" />
    <endEvent id="end" />
    </process>
    </definitions>

    Where Printer looks like this:

    這里 Printer 看起來(lái)如下:

    public class Printer {
    public void printMessage() {
    System.out.println("hello world");
    }
    }

    And the Spring bean configuration (also shown above) looks like this:

    Spring bean配置(如上所示)看起來(lái)如下:

    <beans ...>
    ...
    <bean id="printer" class="org.activiti.examples.spring.Printer" />
    </beans>

    Automatic resource deployment(自動(dòng)資源部署)

    Spring integration also has a special feature for deploying resources. In the process engine configuration, you can specify a set of resources. When the process engine is created, all those resources will be scanned and deployed. There is filtering in place that prevents duplicate deployments. Only when the resources actually have changed, will new deployments be deployed to the Activiti DB. This makes sense in a lot of use case, where the Spring container is rebooted often (eg testing).

    Spring集成也為部署資源提供一個(gè)特殊的特性。在流程引擎配置里,你能指定一系列資源。當(dāng)建立資源引擎時(shí),將掃描并部署所有這些資源。存在一個(gè)防止復(fù)制部署的過(guò)濾器。只有當(dāng)資源實(shí)際上已經(jīng)發(fā)生變化時(shí),才將新的部署才部署到Activiti 數(shù)據(jù)庫(kù)里。這個(gè)需要Spring容器需要經(jīng)常重新引導(dǎo)(比如測(cè)試)的地方才有意義。

    Here's an example

    這里有個(gè)示例

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    ...
    <property name="deploymentResources" value="classpath*:/org/activiti/spring/test/autodeployment/autodeploy.*.bpmn20.xml" />
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>

    Unit testing(單元測(cè)試)

    When integrating with Spring, business processes can be tested very easily using the standard Activiti testing facilities. Following example shows how a business process is tested in a typical Spring-based unit test:

    當(dāng)和Spring集成時(shí),采用標(biāo)準(zhǔn)的測(cè)試設(shè)施Activiti testing facilities讓業(yè)務(wù)流程的測(cè)試輕而易舉。下例展示在一個(gè)典型基于Spring的單元測(cè)試?yán)锩嬉粋€(gè)業(yè)務(wù)流程是如何測(cè)試的。

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:org/activiti/spring/test/junit4/springTypicalUsageTest-context.xml")
    public class MyBusinessProcessTest {
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    @Rule
    public ActivitiRule activitiSpringRule;
    @Test
    @Deployment
    public void simpleProcessTest() {
    runtimeService.startProcessInstanceByKey("simpleProcess");
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    }
    }
    

    Note that for this to work, you need to define a org.activiti.engine.test.ActivitiRule bean in the Spring configuration (which is injected by auto-wiring in the example above).

    注意:為了讓這個(gè)能夠工作,需要在Spring配置里面 定義一個(gè)org.activiti.engine.test.ActivitiRule bean(在上例里通過(guò)auto-wiring 注入)。

    <bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
    <property name="processEngine" ref="processEngine" />
    </bean>
    

    評(píng)論

    # re: Activiti User Guide(Activiti用戶指南)-Chapter 4. Spring integration(Spring集成)[未登錄](méi)  回復(fù)  更多評(píng)論   

    2010-12-29 15:46 by 三木
    博文寫(xiě)的不錯(cuò),能把你的js鼠標(biāo)特效去掉啊

    # re: Activiti User Guide(Activiti用戶指南)-Chapter 4. Spring integration(Spring集成)  回復(fù)  更多評(píng)論   

    2011-01-01 23:26 by 網(wǎng)路冷眼@BlogJava
    @三木
    謝謝光臨!去掉JS特效讓我好好考慮
    主站蜘蛛池模板: 在线观看亚洲av每日更新| 亚洲精品一卡2卡3卡三卡四卡| 亚洲色大情网站www| 青青青国产在线观看免费网站 | 亚洲精品成人图区| 久久黄色免费网站| 日韩免费视频播播| 亚洲国产精品自在自线观看| 成人永久免费高清| 免费无毒a网站在线观看| 亚洲精品老司机在线观看| 国产免费一级高清淫曰本片| 国产精品无码免费播放| 亚洲中文字幕无码不卡电影 | 亚洲精品在线播放视频| 亚洲一级免费视频| 日韩亚洲人成在线| A级毛片高清免费视频在线播放| 日本一道在线日本一道高清不卡免费| 亚洲国产欧洲综合997久久| 亚洲国产精品丝袜在线观看| 丝袜捆绑调教视频免费区| 亚洲Av无码乱码在线znlu| 中文字幕免费播放| 久久精品国产亚洲AV电影| 性一交一乱一视频免费看| 一级毛片免费视频网站| 日韩中文无码有码免费视频| 日日躁狠狠躁狠狠爱免费视频| 18禁无遮挡无码网站免费| 国产亚洲成在线播放va| 久久91亚洲人成电影网站| 成人无码区免费A片视频WWW| 美景之屋4在线未删减免费| 亚洲AV无码成人专区片在线观看| 很黄很黄的网站免费的| 一级毛片视频免费观看| 亚洲成人免费网址| 免费黄色福利视频| 污视频网站在线免费看| 亚洲精品福利网站|