cancel
Showing results for 
Search instead for 
Did you mean: 

Autowiring services in a custom TaskListener for Activiti

varun33
Champ on-the-rise
Champ on-the-rise
Hello Friends,

I created a new customized TaskListener for an Activiti workflow and am trying to access the various Alfresco Services within it like the WorkflowService, NodeService, RuntimeService using the Spring autowire functionality but it is not working.

Please find mentioned below the code written by me and let me know the corrections that I need to make in order to make this work.


{{{
<!–TestTaskListener .java–>
public class TestTaskListener implements TaskListener {
       WorkflowService workflowService;
   NodeService nodeService;
         TransactionService transactionService;
   RuntimeService runtimService;

   @Override
   public void notify(DelegateTask delegateTask) {
               if (null == nodeService) {
         System.out.println("Inside notify - Varun - null");
      } else {
         System.out.println("Inside notify - Varun - NOT null");
      }
   }
}

<!–test-context.xml–>
<bean id="testListener" class="com.ds.task.listeners.TestTaskListener">
      <property name="workflowService" ref="WorkflowService" />
      <property name="nodeService" ref="NodeService" />
      <property name="runtimService" ref="activitiRuntimeService" />
      <property name="transactionService">
         <ref bean="transactionService" />
      </property>
   </bean>
}}}


Thanks,
Varun
9 REPLIES 9

jpotts
World-Class Innovator
World-Class Innovator
Do you have setters defined in your class that correspond to each of the properties you are trying to set with Spring?

Jeff

varun33
Champ on-the-rise
Champ on-the-rise
Yes, setters are defined for all of them.

jpotts
World-Class Innovator
World-Class Innovator

varun33
Champ on-the-rise
Champ on-the-rise
Hi Jeff,

It is somewhat related but that forum does not provide a proper solution to the problem mentioned here.

Some of the other discussion forums mention that Activiti standalone does not use the Spring Application context due to which Dependency Injection is not available when customizing its code, there is a way to modify the process engine configuration of Activiti which allows it to work under the Spring context, but I am not sure how and what modification is required here after Activiti has been integrated inside Alfresco.

Please let me know if you have idea about whether the above is true or not.

Regards,
Varun

jpotts
World-Class Innovator
World-Class Innovator
In my case the "fix" was to use the service registry instead of injecting the beans in Spring config. I'll see if one of the Activiti guys can shed any light.

Jeff

frederikhereman
Champ in-the-making
Champ in-the-making
The activti-integration into Alfresco has no special handling of the spring-context, it's just wired in the main alfresco-context (defined in activiti-context.xml). So if you fail to get services injected into a bean, this is activiti-unrelated. A couple questions to get more insight on your problem:

  • I see you defining property values, but you say in your title "Autowiring". AFAIK, auto wiring won't work in alfresco context

  • How do you connect the existing context (alfresco) with your test-context?

  • What is the exact error? BeanNotFoundExceptions or are the beans just NULL?

  • How do you "hook" in your task listener into the activiti-engine? Using the BPMNParseListener? Or using activiti:delegateExpression?

varun33
Champ on-the-rise
Champ on-the-rise
I see you defining property values, but you say in your title "Autowiring". AFAIK, auto wiring won't work in alfresco context
>>>>I basically meant Dependency Injection over here using the property values defined in the spring beans xml

How do you connect the existing context (alfresco) with your test-context?
>>>>>No special handling has been done for this except for running this as a web extension in Alfresco

What is the exact error? BeanNotFoundExceptions or are the beans just NULL?
>>>>>The properties of the TestTaskListener class do not get initialized which I expect should have been injected using the spring beans xml specified above

How do you "hook" in your task listener into the activiti-engine? Using the BPMNParseListener? Or using activiti:delegateExpression?
>>>>>
<userTask ………………>
<extensionElements>         
<activiti:taskListener event="create"
               class="com.dsny.task.listeners.TestTaskListener2"></activiti:taskListener>
         </extensionElements>
</userTask>

anon26949
Star Contributor
Star Contributor