4

我在我的春季项目中第一次使用 Camunda BPMN2 并试图让我的头脑了解一些事情......

在我的 applicationContext 中,我有以下块来设置 Camunda:

    <!-- Setup BPMN Process Engine -->
    <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
        <property name="processEngineName" value="engine" />
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jobExecutorActivate" value="false" />
        <property name="deploymentResources" value="classpath*:*.bpmn" />
    </bean>
    <bean id="processEngine" class="org.camunda.bpm.engine.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" />
    <context:annotation-config />

我设置了两个服务:

@Component(value="service1")
public class Service1 implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {     
        System.out.println(">>>>>>>>>>>>>>>>>>>");
        System.out.println("SERVICE1");     
        System.out.println(">>>>>>>>>>>>>>>>>>>");      
    }
}

@Component(value="service2")
public class Service2 implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>>>>>");
        System.out.println("SERVICE2");     
        System.out.println(">>>>>>>>>>>>>>>>>>>");
    }
}

在场景 1 中,我有一个调用 Service1 和 Service2 的并行网关(我在 Eclipse 中使用 BPMN2 编辑器构建了这些图表):

情景 1

场景 1 - 服务 1

场景 1 - 服务 2

运行这行代码:

runtimeService.startProcessInstanceByKey("ConnectorSwitch");

打印出来

>>>>>>>>>>>>>>>>>>>
SERVICE1
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
SERVICE2
>>>>>>>>>>>>>>>>>>>

正如预期的那样。

现在我正在尝试放入一个独家网关:

在此处输入图像描述

运行它会给我以下异常:

SEVERE: Error while closing command context                                                                                                                                                                                                 
org.camunda.bpm.engine.ProcessEngineException: Exclusive Gateway 'ExclusiveGateway_3' has outgoing sequence flow 'SequenceFlow_39' without condition which is not the default flow. | ..../ConnectorSwitch.bpmn | line 0 | column 0                                                                                                                                                                                                              
Exclusive Gateway 'ExclusiveGateway_3' has outgoing sequence flow 'SequenceFlow_40' without condition which is not the default flow. | ..../ConnectorSwitch.bpmn | line 0 | column 0                 

        at org.camunda.bpm.engine.impl.util.xml.Parse.throwExceptionForErrors(Parse.java:183)
        at org.camunda.bpm.engine.impl.bpmn.parser.BpmnParse.execute(BpmnParse.java:177)     
        at org.camunda.bpm.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:106)
        at org.camunda.bpm.engine.impl.persistence.deploy.DeploymentCache.deploy(DeploymentCache.java:50)
        at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager.insertDeployment(DeploymentManager.java:42)
        at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:81)                                        
        at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:50)                                        
        at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)            
        at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:90)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) 
    ......

例外很明显,我错过了独占网关上的一个条件。所以我的问题是,如何为独占网关分配条件,如何调用某个类中的方法并评估真/假,以及如果我想为 service1 / service2 调用不是 JavaDelegate 的其他东西(换句话说,MyClass.doSomethingWithParams(someparam)),我该怎么做呢?

XML 中的答案也很好,宁愿学习如何在 XML 中使用 BPMN2,而不是依赖于 BPMN2 视觉效果。

4

1 回答 1

12

Camunda Modeler中,单击来自您的专属网关的序列流之一。然后选择Properties窗格和子窗格General。您将看到一个属性Condition。可以使用 JUEL 表达式填充此属性,就像您用于代表的那个一样。您可以在那里使用您的 Spring bean,例如调用它们的方法。因此,如果myClass是 Spring bean 名称,只需编写${myClass.doSomethingWithParams(someparam)}. 或者您可以访问已经附加到您的流程实例的流程变量。someparam可能是这样一个变量,例如 -> 只要确保所有传出的序列流都附加了这样的条件。然后您的进程将再次运行。也许首先从一个简单的条件开始,比如${true}${false}. 如果这可行,请继续做一些更复杂的事情。玩得开心!:-)

于 2014-11-20T13:19:46.803 回答