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);
}
}
Solved! Go to Solution.
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
Which version are you using?
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.
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
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.
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
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.