天天看点

Flowable 6.6.0 BPMN用户指南 - 15 CDI集成 - 15.1 设置flowable-cdi《Flowable 6.6.0 BPMN用户指南》

Flowable 6.6.0 用户指南相关文档下载

  • BPMN用户指南 第一部分 - 中文PDF精编版
  • BPMN用户指南 第二部分 - 中文PDF精编版
  • BPMN用户指南 第三部分 - 中文PDF精编版
  • 应用程序指南 - 中文PDF精编版
  • 应用程序指南 - 中英对照PDF精编版
  • 应用程序指南 - Eclipse设计器中文PDF精编版
  • 表单用户指南 - 中文PDF精编版
  • 事件注册表用户指南 - 中文PDF精编版

《Flowable 6.6.0 BPMN用户指南》

1. 入门

2. 配置

3 The Flowable API

4 Flowable 6.6.0 BPMN用户指南 - (4)Spring集成

5 Spring Boot

6 部署

7 BPMN 2.0简介

8 BPMN 2.0的构造

9 表单(Forms)

10 流程实例迁移

11 JPA

12 历史(History)

13 身份管理(Identity management)

14 REST API

15 CDI集成

  • 15.1 设置flowable-cdi
  • 15.2 使用CDI的上下文流程执行(Contextual Process Execution with CDI)
    • 15.2.1 实现会话与流程实例的关联(Associating a Conversation with a Process Instance)
    • 15.2.2 通过声明控制流程(Declaratively controlling the Process)
    • 15.2.3 从流程引用Bean(Referencing Beans from the Process)
    • 15.2.4 使用@BusinessProcessScoped bean
    • 15.2.5 注入流程变量(Injecting Process Variables)
    • 15.2.6 接收流程事件(Receiving Process Events)
    • 15.2.7 其它特征(Additional Features)
  • 15.3 已知限制

有关Flowable的更多文档,参见:

《Flowable文档大全》

15 CDI集成

The flowable-cdi modules leverages both the configurability of Flowable and the extensibility of cdi. The most prominent features of flowable-cdi are:

flowable-cdi模块充分利用了Flowable的可配置性和cdi的可扩展性。flowable-cdi最突出的特点是:

  • Support for @BusinessProcessScoped beans (CDI beans whose lifecycle is bound to a process instance),
  • A custom El-Resolver for resolving CDI beans (including EJBs) from the process,
  • Declarative control over a process instance using annotations,
  • Flowable is hooked-up to the CDI event bus,
  • Works with both Java EE and Java SE, works with Spring,
  • Support for unit testing.
  • 支持@BusinessProcessScoped bean(生命周期绑定到流程实例的CDI bean),
  • 用于从流程中解析CDI bean(包括EJB)的定制El-Resolver,
  • 使用注解对流程实例进行声明性控制,
  • Flowable连接到CDI事件总线,
  • 可与Java EE和Java SE协同工作,可与Spring配合使用,
  • 支持单元测试。
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-cdi</artifactId>
    <version>6.x</version>
</dependency>
           

15.1 设置flowable-cdi

Flowable-cdi can be set up in different environments. In this section we briefly walk through the configuration options.

Flowable-cdi可以在不同的环境中设置。在本节中,我们将简要介绍配置选项。

15.1.1 查找流程引擎

The CDI extension needs to get access to a ProcessEngine. To achieve this, an implementation of the interface org.flowable.cdi.spi.ProcessEngineLookup is looked up at runtime. The CDI module ships with a default implementation named org.flowable.cdi.impl.LocalProcessEngineLookup, which uses the ProcessEngines-Utility class for looking up the ProcessEngine. In the default configuration ProcessEngines#NAME_DEFAULT is used to look up the ProcessEngine. This class might be subclassed to set a custom name. NOTE: You need a flowable.cfg.xml configuration on the classpath.

CDI扩展需要访问ProcessEngine。为了实现这一点,在运行时查找接口org.flowable.cdi.spi.ProcessEngineLookup的实现。CDI模块附带一个名为org.flowable.cdi.impl.LocalProcessEngineLookup的默认实现,它使用ProcessEngines-Utility类查找ProcessEngine。在默认配置中,使用ProcessEngines#NAME_DEFAULT来查找ProcessEngine。该类可能被子类化以设置自定义名称。注意:你需要一个类路径(classpath)上的flowable.cfg.xml 配置。

Flowable-cdi uses a java.util.ServiceLoader SPI for resolving an instance of org.flowable.cdi.spi.ProcessEngineLookup. In order to provide a custom implementation of the interface, we need to add a plain text file named META-INF/services/org.flowable.cdi.spi.ProcessEngineLookup to our deployment, in which we specify the fully qualified class name of the implementation.

Flowable-cdi使用java.util.ServiceLoader SPI来解析org.flowable.cdi.spi.ProcessEngineLookup。为了提供接口的自定义实现,我们需要添加一个名为META-INF/services的纯文本文件META-INF/services/org.flowable.cdi.spi.ProcessEngineLookup到我们的部署中,在此我们指定实现的完全限定类名。

Note

If you do not provide a custom org.flowable.cdi.spi.ProcessEngineLookup implementation, Flowable will use the default LocalProcessEngineLookup implementation. In that case, all you need to do is providing a flowable.cfg.xml file on the classpath (see next section).

注意

如果你不提供自定义org.flowable.cdi.spi.ProcessEngineLookup实现,Flowable将使用默认的LocalProcessEngineLookup实现。在这种情况下,您只需在类路径上提供flowable.cfg.xml文件(见下一节)。

15.1.2 配置流程引擎

Configuration depends on the selected ProcessEngineLookup-Strategy (cf. previous section). Here, we focus on the configuration options available in combination with the LocalProcessEngineLookup, which requires us to provide a Spring flowable.cfg.xml file on the classpath.

Flowable offers different ProcessEngineConfiguration implementations mostly dependent on the underlying transaction management strategy. The flowable-cdi module is not concerned with transactions, which means that potentially any transaction management strategy can be used (even the Spring transaction abstraction). As a convenience, the CDI module provides two custom ProcessEngineConfiguration implementations:

配置取决于所选的ProcessEngineLookup-Strategy(参见上一节)。这里,我们将重点介绍与LocalProcessEngineLookup结合使用的配置选项,它要求我们在类路径(classpath)上的提供一个Spring flowable.cfg.xml文件。

Flowable提供了不同的ProcessEngineConfiguration实现,这些实现主要依赖于底层事务管理策略。flowable-cdi模块不关注事务,这意味着可以使用任何事务管理策略(甚至Spring事务抽象)。为了方便起见,CDI模块提供了两个自定义ProcessEngineConfiguration实现:

  • org.flowable.cdi.CdiJtaProcessEngineConfiguration: a subclass of the Flowable JtaProcessEngineConfiguration can be used if JTA-managed transactions should be used for Flowable
  • org.flowable.cdi.CdiStandaloneProcessEngineConfiguration: a subclass of the Flowable StandaloneProcessEngineConfiguration can be used if plain JDBC transactions should be used for Flowable. The following is an example flowable.cfg.xml file for JBoss 7:
  • org.flowable.cdi. CdiJtaProcessEngineConfiguration:如果应将JTA托管事务(JTA-managed transaction)用于Flowable,则可以使用Flowable JtaProcessEngineConfiguration的子类
  • org.flowable.cdi. CdiStandaloneProcessEngineConfiguration:如果将普通JDBC事务用于Flowable,则可以使用Flowable StandaloneProcessEngineConfiguration的子类。下面是一个JBoss 7的例子flowable.cfg.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- lookup the JTA-Transaction manager -->
    <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:jboss/TransactionManager"></property>
        <property name="resourceRef" value="true" />
    </bean>

    <!-- process engine configuration -->
    <bean id="processEngineConfiguration"
        class="org.flowable.cdi.CdiJtaProcessEngineConfiguration">
        <!-- lookup the default Jboss datasource -->
        <property name="dataSourceJndiName" value="java:jboss/datasources/ExampleDS" />
        <property name="databaseType" value="h2" />
        <property name="transactionManager" ref="transactionManager" />
        <!-- using externally managed transactions -->
        <property name="transactionsExternallyManaged" value="true" />
        <property name="databaseSchemaUpdate" value="true" />
    </bean>
</beans>
           

And this is how it would look like for Glassfish 3.1.1 (assuming a datasource named jdbc/flowable is properly configured):

Glassfish 3.1.1的情况如下(假设名为jdbc/flowable的数据源配置正确):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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">

    <!-- lookup the JTA-Transaction manager -->
    <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:appserver/TransactionManager"></property>
        <property name="resourceRef" value="true" />
    </bean>

    <!-- process engine configuration -->
    <bean id="processEngineConfiguration"
        class="org.flowable.cdi.CdiJtaProcessEngineConfiguration">
        <property name="dataSourceJndiName" value="jdbc/flowable" />
        <property name="transactionManager" ref="transactionManager" />
        <!-- using externally managed transactions -->
        <property name="transactionsExternallyManaged" value="true" />
        <property name="databaseSchemaUpdate" value="true" />
    </bean>
</beans>
           

Note that the above configuration requires the “spring-context” module:

请注意,上述配置需要“spring-context”模块:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.5.RELEASE</version>
</dependency>
           

The configuration in a Java SE environment looks exactly like the examples provided in section Creating a ProcessEngine, substitute CdiStandaloneProcessEngineConfiguration for StandaloneProcessEngineConfiguration.

Java SE环境的配置与创建ProcessEngine(Creating a ProcessEngine)一节中提供的示例完全相同,请将CdiStandaloneProcessEngineConfiguration替换为StandaloneProcessEngineConfiguration。

15.1.3 部署流程(Deploying Processes)

Processes can be deployed using the standard Flowable API (RepositoryService). In addition, flowable-cdi offers the possibility to auto-deploy processes listed in a file named processes.xml located top-level in the classpath. This is an example processes.xml file:

可以使用标准的Flowable API(RepositoryService)部署流程。此外,flowable-cdi还提供了自动部署流程的可行性,流程在processes.xml列出,processes.xml文件位于类路径(classpath)的顶层。这是一个例子流程.xml文件:

<?xml version="1.0" encoding="utf-8" ?>
<!-- list the processes to be deployed -->
<processes>
    <process resource="diagrams/myProcess.bpmn20.xml" />
    <process resource="diagrams/myOtherProcess.bpmn20.xml" />
</processes>

           

继续阅读