cancel
Showing results for 
Search instead for 
Did you mean: 

@Inject Not Working in Delegate - Activiti 5.12.1

zoikks1
Champ in-the-making
Champ in-the-making
I have built a custom service task that defines the task (UI) and then has a delegate associated with it.  Inside the delegate, I'd like to inject an EJB using @Inject.  When I execute the functionality, the injection never seems to happen.  A similar structure for what I have created is here:

public class MyDelegate implements JavaDelegate {

  @Inject
  @EjbQualifier
  private MyEjb myEjb;

  public MyDelegate() {  }

  @Override
  public void execute(DelegateExecution execution) throws Exception {..}
}

I have ensured my beans.xml file is properly entered into the JAR.  The call to startProcessInstanceByKey(…) is called from within an EJB running in a WebLogic 12 application server.  Can anyone give me any insight about why the injection is not occurring?

Thanks.
9 REPLIES 9

trademak
Star Contributor
Star Contributor
Hi,

If you want to use an EJB in a service task you have to first look it up in the JNDI context.
This injection doesn't work for service tasks.

Best regards,

zoikks1
Champ in-the-making
Champ in-the-making
Thanks for the reply.

Fair enough - what is preventing the injection from working?

frederikherema1
Star Contributor
Star Contributor
Delegate instances (if using activiti:class) are instantiated by activity by it's classname, simple as that. So the annotations won't be processed. You can try adding the JavaDelegate instance (initialized and fetched with everything injected) as a "bean" to the process-engine configuration and use activiti:delegateExpression="${theDelegate}"

yuryshaban
Champ in-the-making
Champ in-the-making
Hello.
Could you please explain me the difference between:
- "This injection doesn't work for service tasks."
- "A custom El-Resolver for resolving Cdi beans (including EJBs) from the process," - from User guide, Section CDI Integration, Chapter 16.

As I understood, CDI works everywhere, but service tasks. Am I right?

Thanks for advance.

frederikherema1
Star Contributor
Star Contributor
When you use activiti:class="org.whatever.MyDelegate", the MyDelegate instance will NOT be aware of CDI-context and injection will not work. Instead, make a CDI-bean of the MyDelegate and register this in the CDI-context (e.g. under the name myDelegate). In a service-task, you can now use the activiti:delegateExpression="${myDelegate}" to use the MyDelegate instance that lives in the CDI-context. This way, injection will work on the bean.

yuryshaban
Champ in-the-making
Champ in-the-making
Thanks a lot!

frederikherema1
Star Contributor
Star Contributor
I presume it's working that way?

yuryshaban
Champ in-the-making
Champ in-the-making
I'm trying.
Now, after your answer, I'm sure, that it's possible to reach what I want (I want EJB through CDI in my service task without lookup(…)) and I'll try till success.
May say, you've presented me hope  Smiley Happy

yuryshaban
Champ in-the-making
Champ in-the-making
Interim result: in JBoss all work great, but weblogic take a firm stand… (because of an older version of Weld. Seems).
We'll continue.