cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Spring Bean in CDI environment

daniel1
Champ in-the-making
Champ in-the-making
Hi,

we have written quite a few spring beans in the past and would like to reuse those in a activiti project. Therefore i declared them in activiti.cfg.xml.
Naively I tried to resolve them using @Named annotation in my backingbean using JBoss AS/Weld. This - as I learned - isn't working out of the box. Now one solution could be to write my own CDI Extension, which would, to my understanding, create a second spring container including processEngine.

So my question now is how can i reuse the processEngine CDI Extension org.activiti.cdi.impl.ActivitiExtension to get access to the spring context. How do other people solve that spring cdi gap?

thx in advance,
Daniel
5 REPLIES 5

meyerd
Champ on-the-rise
Champ on-the-rise
You could check out the jboss seam module:

http://docs.jboss.org/seam/3/spring/latest/reference/en-US/html/spring-usage.html

I have no Idea how good it is, though.

daniel1
Champ in-the-making
Champ in-the-making
Thx for the link. With some more tweaking (Spring Securitys AuthenticationManager is not really unique) i got it up and running in my managed beans now.

Now my next problem arises: i can't inject my beans in JavaDelegates as beans get constructed by activiti and not by CDI. Is there some way to access
CDIs BeanManager via Context.getProcessEngineConfiguration().something?

Maybe you have another great link for me? Smiley Wink

meyerd
Champ on-the-rise
Champ on-the-rise
Hi daniel,

You can annotate your JavaDelegate classes with @Named:

@Named
public class MyDelegate implements JavaDelegate {

public void execute(DelegateExecution ex) throws Exception {

}

}

and in your service task:

<serviceTask … activiti:delegateExpression="myDelegate" />

This way the instance of MyDelegae is constructed by the CDI Container and not by activiti and you can use CDI services such as Injection, Interceptors etc….

daniel1
Champ in-the-making
Champ in-the-making
Hi Daniel,

great! Really clever to do it that way.

One addition i do have to your solution:

<serviceTask … activiti:delegateExpression="myDelegate" />

should be

<serviceTask … activiti:delegateExpression="#{myDelegate}" />

Thanks again!

meyerd
Champ on-the-rise
Champ on-the-rise
:shock: OMG yes… I should not answer posts before drinking my morning coffee Smiley Happy