我在我的春季项目中第一次使用 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 编辑器构建了这些图表):
运行这行代码:
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 视觉效果。