cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic injcection of values does not work in Spring context

pposch
Champ in-the-making
Champ in-the-making
Hi,
we are setting up an application using Activiti and Spring. We have problems in injecting dynamic variables at runtime. The variant:

<serviceTask id="javaService"
             name="My Java Service Task"
             activiti:class="xxx.MyTask" >
            <extensionElements>
                       <activiti:field name="user">
                            <activiti:expression>${method.foo()}</activiti:expression>
                       </activiti:field>
           </extensionElements>
</serviceTask>

works fine but the execute method in "xxx.MyTask" is executed outside our Spring context. That means that Spring injections do not work.
In the variant:

<serviceTask id="javaService"
             name="My Java Service Task"
             activiti:delegateExpression="${mybean}">
            <extensionElements>
                       <activiti:field name="user">
                            <activiti:expression>${method.foo()}</activiti:expression>
                       </activiti:field>
           </extensionElements>
</serviceTask>

the task "${mybean}" is executed in our Spring context, but the injection of the variable "user" does not work. Is there any possibility (existing or planned) to have dynamic variable injection and the Spring context at the same time?
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
If youre using SpringProcessEngineCOnfiguration, the full spring-context (the context where the activiti engine is defined) is available (make sure you don't use a regular non-spring configuration). All expressions are resolved at RUNTIME, so fetched from the app-context when the expression is evaluated = when service-task actually runs.

pposch
Champ in-the-making
Champ in-the-making
We are actually using SpringProcessEngineConfiguration and the Spring context is available with the only exception when we use activiti:class in our serviceTask. In this case the Spring context is empty.

frederikherema1
Star Contributor
Star Contributor
I see what you mean… The injections are only performed on classes that are instantiated by activiti itself. As you know, this only happens one time (the Expression objects are injected, value resolving happens based on the DelegateExecution) -> single javaDelegate is used for all processes.

Since the delegateExpression can return anything and is potentially already configured, no field injections are done on this. All process-context can be fetched from the DelegateExecution, all non-process dependant stuff can be wired in by Spring I guess…