Hi!
I’m trying to add listener to all user tasks. So I’ve decided to create a plugin using this example. But my plugin never gets called and so my listener. What am I missing?
Plugin:
public class ListenerPlugin extends AbstractProcessEnginePlugin {
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
System.out.println("ListenerPlugin: Adding custom parse listener");
// init custom bpmn parsers
List<BpmnParseListener> parseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
if (parseListeners == null) {
parseListeners = new ArrayList<>();
processEngineConfiguration.setCustomPreBPMNParseListeners(parseListeners);
}
parseListeners.add(new BpmnParseParser());
}
}
Parse listener:
public class BpmnParseParser extends AbstractBpmnParseListener {
@Override
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
System.out.println("BpmnParseParser: Adding listener to user task");
activity.addListener(TaskListener.EVENTNAME_CREATE, new GlobalUserTaskListener());
}
}
Listener:
public class GlobalUserTaskListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
System.out.println("GlobalUserTaskListener: processInstanceId = '" + execution.getProcessInstanceId() + "'");
}
}
applicationContext.xml
<!-- bind the process engine service as Spring Bean -->
<bean name="processEngineService" class="org.camunda.bpm.BpmPlatform" factory-method="getProcessEngineService"/>
<!-- bind the default process engine as Spring Bean -->
<bean name="processEngine" factory-bean="processEngineService" factory-method="getDefaultProcessEngine"/>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>
<bean id="processEngineConfiguration"
factory-bean="processEngine" factory-method="getProcessEngineConfiguration">
<property name="processEnginePlugins">
<list>
<bean class="ru.my.plugins.ListenerPlugin" />
</list>
</property>
</bean>
<!-- bootstrap the process application -->
<bean id='myProcessApplication'
class="org.camunda.bpm.engine.spring.application.SpringServletProcessApplication"/>