AnsweredAssumed Answered

Activiti 6: Inject custom TaskListener programmatically

Question asked by dennie.oberlatz on May 19, 2016
Latest reply on May 31, 2016 by dennie.oberlatz

I am currently migrating from activiti 5.20.0 to 6.0.0.Beta2. The project is a spring boot (version: 1.3.5.RELEASE) project with activiti integration.

My goal is to inject a custom task listener via Java. I am facing a problem with my current approach due to an API change in activiti 6.

How I have solved the problem so far:
In activiti 5 a custom task listener is injected by overriding the method DefaultActivityBehaviorFactory::createUserTaskActivityBehavior(UserTask userTask, TaskDefinition taskDefinition) and setting the custom listener to the taskDefinition. The custom DefaultActivityBehaviorFactory replaces the original one in the SpringProcessEngineConfiguration.

Custom DefaultActivityBehaviorFactory:
public class MyActivityBehaviorFactory extends DefaultActivityBehaviorFactory {

    TaskListener userTaskCreatedListener;

    public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask, TaskDefinition taskDefinition) {
        taskDefinition.addTaskListener(TaskListener.EVENTNAME_CREATE, userTaskCreatedListener);
        return super.createUserTaskActivityBehavior(userTask, taskDefinition);

Register custom DefaultActivityBehaviorFactory:
public class ActivitiConfiguration {

    MyActivityBehaviorFactory myActivityBehaviorFactory;

    public BeanPostProcessor activitiConfigurer() {
        return new BeanPostProcessor() {

            public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
                // inject custom behavior into the activiti process engine
                // configuration
                if (bean instanceof SpringProcessEngineConfiguration) {
                    ((SpringProcessEngineConfiguration) bean).setActivityBehaviorFactory(myActivityBehaviorFactory);
                return bean;

In activiti 6 that does not work anymore because the method DefaultActivityBehaviorFactory::createUserTaskActivityBehavior(ExpressionManager expressionManager, UserTask userTask) does not provide the taskDefinition anymore.

A link to a migration guide from activiti 5 to 6 or a hint on how to solve my problem would be appreciated.
Best regards,