AnsweredAssumed Answered

Problem with field injection with Spring proxy

Question asked by brendenr on Feb 22, 2017
Latest reply on Feb 24, 2017 by thuynh

Hi, I am trying to use field injection on a JavaDelegate service and am having an issue with Spring where activiti is trying to get/set the field on the service object but Spring is proxying that object (via JdkDynamicAopProxy) and activiti can't find the field through the proxy.

 

The XML for the service task is defined as:

<serviceTask id="sid-123" name="Correlation1" activiti:delegateExpression="${correlationService}">
    <extensionElements>
        <activiti:field name="correlationName" stringValue="Correlation1"/>
    </extensionElements>
</serviceTask>

Then the service task is defined as:

@Service
public class CorrelationService implements JavaDelegate {
public Expression correlationName;
    @Override
    public void execute(DelegateExecution execution) throws Exception {
         // code omitted...
    }
}

Now when that service task is activated in the activiti process, it gets hung up trying to pass that correlationName variable and throws the error listed below.

[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.activiti.engine.ActivitiIllegalArgumentException: Field definition uses unexisting field 'correlationName' on class com.sun.proxy.$Proxy143] with root cause
org.activiti.engine.ActivitiIllegalArgumentException: Field definition uses unexisting field 'correlationName' on class com.sun.proxy.$Proxy143
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.applyFieldDeclaration(ClassDelegate.java:283) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.applyFieldDeclaration(ClassDelegate.java:256) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.helper.DelegateExpressionUtil.resolveDelegateExpression(DelegateExpressionUtil.java:43) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior.execute(ServiceTaskDelegateExpressionActivityBehavior.java:85) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97) ~[activiti-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:650) ~[activiti-engine-5.22.0.jar:5.22.0]

....

Here's a couple debug screenshots showing where the proxy is in place of the actual object:

Outcomes