Search code examples
javabpmncamundabusiness-process-managementcamunda-modeler

Camunda Service Task Error : Unknown property used in expression


I created a simple workflow where I am calling an event subprocess in another process using a service task and I am doing this by using a Java code. I configured the java class in the service task using the Implementation type "Delegate Expression" (see below)

enter image description here

I get the following error while running the service task.

An error happened while submitting the task form : Cannot submit task form 54897af5-dc6b-11ec-85f0-e02be903a6c0: Unknown property used in expression: #{cancelProcess}. Cause: Cannot resolve identifier 'cancelProcess'

Here is my Java code :

package org.example;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.runtime.MessageCorrelationResult;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component("cancelProcess")
public class CancelProcess implements JavaDelegate {
    public void execute(DelegateExecution execution) {
        // correlate the message
        RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
        MessageCorrelationResult result = runtimeService.createMessageCorrelation("CANCEL_PROCESS")
                .processInstanceBusinessKey("Order-Process-123")
                .setVariable("employeeName", execution.getVariable("employeeName"))
                .correlateWithResult();
    }
}

Please advise. What mistake am I making here.


Solution

  • You correctly used the implementation type delegate expression and inside the expression the name of the spring bean. If the name of the component cannot be resolved then it could be that the component has not been detected. Does the log show that the declaration is found?

    Spring's component scan only automatically picks up on components which are declared in a package below the package your Application resides in. See e.g. https://www.baeldung.com/spring-component-scanning

    Try placing your main application class in a root package above the component classes.