cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Custom Execution Listener During Transition of Sequence Flow

dharamjeet
Confirmed Champ
Confirmed Champ

   I extended SequenceFlowParseHandler for setting executionListener to sequence flow. By doing so I am able to execute my custom listener everytime a transition happens in the workflow.

ActivitiListener activitiListener = new ActivitiListener();
activitiListener.setEvent(ExecutionListener.EVENTNAME_START);
activitiListener.setImplementation("${customExecutionListener}");
activitiListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);

 I am using delegate Expression for implementation type but class fails to autowire beans in my customExecutionListener I dont know where i'm going wrong.

1 ACCEPTED ANSWER

gdharley
Elite Collaborator
Elite Collaborator

Likely this is because your listener is running on a servlet thread that is not part of the spring application context.

One option is to use an application Context provider:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ApplicationContextProvider implements ApplicationContextAware{
     private static ApplicationContext context;
     public static ApplicationContext getApplicationContext() {    
         return context;
     }

@Override    public void setApplicationContext(ApplicationContext ac) throws BeansException {
        context = ac;
    }
}

This way you can retrieve the Spring application context and then the bean you need.

Greg

bp3‌

View answer in original post

1 REPLY 1

gdharley
Elite Collaborator
Elite Collaborator

Likely this is because your listener is running on a servlet thread that is not part of the spring application context.

One option is to use an application Context provider:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ApplicationContextProvider implements ApplicationContextAware{
     private static ApplicationContext context;
     public static ApplicationContext getApplicationContext() {    
         return context;
     }

@Override    public void setApplicationContext(ApplicationContext ac) throws BeansException {
        context = ac;
    }
}

This way you can retrieve the Spring application context and then the bean you need.

Greg

bp3‌