Spring Boot + Camunda Service Task - Expression Example
Implementation Types:
- Java Delegate
- Expression
- Delegate Expression
- External Service Task
- Connector

Spring Boot Camunda Tutorials
Spring Boot + Camunda Hello World Example. Spring Boot + Camunda Script Task Example. Spring Boot + Camunda Service Task - Java Delegate Example. Spring Boot + Camunda Service Task - Delegate Expression Example. Spring Boot + Camunda Service Task - Expression Example.
Implementation
Download the source code we had implemented in Spring Boot + Camunda Service Task - Java Delegate Example.The maven project we will be creating is as follows-


Now we will make use of expression. Now instead of using delegate expression for specifying the service task we will be making use of expression where we specify the bean name along with the method name. So select the implementation as a delegate expression. The expression will be of the format - ${beanName.methodName(execution)}. The execution variable is automatically available in the expression context in Camunda. In our case the bean name will be the java class name in camel case along with the method name which is ${confirmationEmail.sendMail(execution)}

Create a new class named ConfirmationEmailExpression. This will be similar to the previous ConfirmationEmailExpressionDelegate class we had created.
package com.example.workflow.delegate.mail; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.springframework.stereotype.Component; @Component public class ConfirmationEmail { public void sendMail(DelegateExecution execution) throws Exception { System.out.println("Sending mail that transaction of order of amount " + execution.getVariable("orderTotal") + " is a " + execution.getVariable("paymentStatus")); } }We rename this bpmn file as fourth.bpmnn with id - fifth-javainuse. Copy this fifth.bpmn in the resources folder. Also we modify the spring boot application to make use of the fifth.bpmn we just created.

Also in the controller class we make the change to use the bpmn diagram with id - fifth-javainuse
package com.example.workflow; import org.camunda.bpm.engine.ProcessEngine; import org.camunda.bpm.engine.ProcessEngines; import org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @GetMapping("/executetask") public String execute() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); ProcessInstantiationBuilder instance = engine.getRuntimeService().createProcessInstanceByKey("fifth-javainuse"); instance.executeWithVariablesInReturn(); return "Executed Camunda BPMN"; } }

Download Source Code
Download it -Spring Boot 3 + Camunda Service Task - Expression Example