05-05-2017 05:32 PM
Hi,
I am writing a custom TaskListener with the below code: I have hooked this TaskListener to Complete event of a User Task. I noticed that all the Autowired objects are null.
I am not efficient in Spring, am I missing a step by which I can properly Autowire these objects? Please assist!
Regards.
Sample Code:
package com.activiti.extension.bean;
@Component("customTaskListener")
public class CustomTaskListener implements TaskListener {
private static final long serialVersionUID = 4218009794670685270L;
private static final Logger logger = LoggerFactory.getLogger(CustomTaskListener.class);
@Autowired
private HistoryService historyService;
@Autowired
private UserService userService;
@Override
public void notify(DelegateTask delegateTask) {
//...removed custom code for this post
//Here userService is null
User subTaskUser = userService.getUser(subTaskAssigneeId);
}
}
05-08-2017 10:01 AM
I'm confused. Can you share a simple bpmn xml showing your Task Listener configuration? Otherwise, please find attached a simple process showing the use of task listener.
Ciju
05-05-2017 07:34 PM
Which version are you using?
05-06-2017 10:46 AM
Hi Ciju Joseph,
The versions are as below:
<activiti.version>1.5.3</activiti.version>
<activiti.engine.version>5.21.0.3</activiti.engine.version>
<spring.version>4.1.6.RELEASE</spring.version>
Deployment is on Alfresco Activiti Enterprise 1.5.3, tried the same with Activiti Process Services 1.6 too with same problem.
I was reading in the admin guide and community regarding bean injections into service task through expressions and JavaDelegate. But in my case it is a TaskListener... I am not quite sure how to go about it.
I read a community post: Injecting a Service in a TaskListener returns Null
where Dirla Vasile mentions: "in order to have properly injected the services you should use expression or delegateExpression.
if you really need to use "class" for setting the listener, then you have to use Expression for the userService and evaluate it at runtime in the notify method."
Any pointers from your end would help!!!!
Appreciate your assistance..... Thank you....
Regards.
05-08-2017 10:01 AM
05-08-2017 11:20 AM
Hi Ciju,
Your example bpmn xml helped me fix the problem.
I was calling the TaskListener by mentioning the class name and not through delegateExpression. Once I removed the class name and used delegateExpression alone then the Autowired Objects were initialized properly.
Sorry I couldn't explain it better.
Yet again... Thank you...
Regards.
05-08-2017 11:26 AM
Bean injection won't work with "class". When you use Java Delegates, Task Listeners and Event Listeners it is important to understand the usage of "class", "delegate expression" and "expression". Check this out for more detailshttps://community.alfresco.com/community/bpm/blog/2016/11/15/activiti-enterprise-developer-series-se...
Ciju
Explore our Alfresco products with the links below. Use labels to filter content by product module.