Integration with Google Guice

Hi guys,

is it possible to use Google Guice for dependency injection within a Camunda process application? How would I do that?

What I want to achieve is to be able to inject some utility classes into my JavaDelegate classes. Like this:

public class MyTaskDelegate implements JavaDelegate {
    
    @Inject
    private MailSender mailSender;

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

	...
        mailSender.send(...);

    }

}

Any clues?

Thanks!
Frank

Ik you run Camunda in an Application Server, you can use Delegate Expressions. Named beans that implement the JavaDelegate interface.

No need for Google Guice.

https://docs.camunda.org/manual/7.5/user-guide/cdi-java-ee-integration/

Thank you for your response.

However we are running Camunda on Tomcat so I’m looking for a Non-EJB solution.

Are you amenable to use of Spring?

I guess it is doable with Guice or Weld as there is an open support ticket in the Camunda sprint backlog to document it.

https://app.camunda.com/jira/browse/CAM-1926

I’d like to avoid using Spring :sunglasses:
It’s just a small and lightweight application and besides Dependency Injection there is no need for any other framework.

Hi Frank,

If you aren’t tied to GG, you can use Weld on Tomcat. Just google on how to bootstrap Weld inside Tomcat, then you just need to add the camunda-engine-cdi.jar to your ProcessApplication and it should work.
Basically we do the same in our QA integration testsuite for Tomcat.
We add Weld to each ProcessApplication deployment in our testsuite for the shared process engine on Tomcat like that:

  1. Add the Weld libraries to the deployment, specifically for Tomcat the weld-servlet. Maven coordinates org.jboss.weld.servlet:weld-servlet
  2. Add a context.xml file to the process application referencing the Weld BeanManager - https://github.com/camunda/camunda-bpm-platform/blob/master/qa/integration-tests-engine/src/test/resources-tomcat/context.xml
  3. Bootstrapping Weld for each ProcessApplication by adding the following marked lines to the web.xml - https://github.com/camunda/camunda-bpm-platform/blob/master/qa/integration-tests-engine/src/test/resources-tomcat/web.xml#L6-L14

Cheers,
Christian

1 Like

Sounds great, I will try this. Thank you!