Posts in Category: spring

“Orchestrating Work with Activiti and Spring Integration” by Josh Long

When my buddy Josh Long from Pivotal writes about Activiti and Spring, it’s always must-read material. No exception this time, so I do want to give it exposure here too:

Orchestrating Work With Activiti and Spring Integration

Nice conclusion too: “BPM adds a fair amount of cognitive load for simple integrations but offers a lot of value when business process descriptions must be model- and business analyst-friendly. One common misconception is that developers have to give up the ability to enhance the system once BPM is involved; NOT SO! Thanks to Spring Boot and some hard work from the Activiti team, Activiti works perfectly with all of Spring.”


Edit 11 Feb 2016: as promised in the comments below, forked the example and made it running on v6:

Activiti on !

In case you missed the following tweet last week


That’s right! Activiti is now on!

This is a huge deal – the Spring Initializr is the place where the journey for many Spring Boot projects start, so being on that page is a huge honour for us. Of course, couldn’t have done it without the help of my Spring friends Josh Long (who also contributed the Spring Boot + Activiti code) and Stéphane Nicoll.

And just to prove how awesome it is, here’s a short movie that starts on and finishes with a REST endpoint that starts a process instance is about 5 minutes!

Getting started with Activiti and Spring Boot published on The Spring Blog!

My article “Getting started with Activiti and Spring Boot” has been published today on The Spring Blog:

It fills me with great pride to be published there. I’ve been a fan of Spring for many years and believe that it houses many of the awesome developers in current Java-land. Anyway, please give the article a read and if you have any remarks/questions/whatever please add it on the article there, not here.

Activiti + Spring Boot docs and example

With the Activiti 5.17.0 release going out any minute now, one of the things we did was writing down documentation on how to use this release together with Spring Boot. If you missed it, me and my Spring friend Josh Long did a webinar a while ago about this.

You can find the new docs already on github master (scroll down to ‘Spring Boot’ section): You can also see we switched to Asciidoc for our docs a couple of weeks ago. And GitHub renders that natively, which is awesome.

While I was writing the documentation, I created a sample application to verify all the stuff in there actually works.  You can find that example here: It has tags for each of the steps (which match the steps in the docs). So to start, checkout tag step-1 and so forth.

This is the first ‘official’ release of the integration (it was in snapshot versions before), so do give it a spin and let us know what you think about it!


Webinar ‘Process Driven Spring Applications with Activiti’ now on Youtube

As I mentioned, I did a webinar on Spring Boot + Activiti last week (at 6 am …. yes, it hurt) with my good pal Josh Long.

If you missed it, or want to see the awesomeness again, here’s the recording:


On a similar note, the webinar that Josh did before this one, on Spring Boot / Spring Cloud is *really* awesome. All this micro-service architecture stuff suddenly made a lot of sense and all the pieces of the puzzle fell together by watching this webinar. Go check it out (after the Activiti webinar, obviously ;-)), it’s well worth your time.

Tutorial: call an EJB in a BPMN 2.0 process using Activiti and Spring

Since its conception, Activiti has always had a great integration with Spring. In this tutorial, I’m going to demonstrate how this integration can be leveraged to call an EJB (the approach works for EJB versions 2 or 3) in a BPMN 2.0 process. Whether you like them or not: the fact is that much business logic has been/is being written in EJB’s, but luckily Activiti makes calling an EJB plain, simple and fun.

The environment for this tutorial is as follows:

  • Activiti 5.1
  • Spring 3.something
  • JBoss 5.1.0

The EJB I’ll use for this tutorial is probably the dullest piece of ‘logic’ you’ve ever seen: it does nothing more than transform the given String parameter to uppercase and return it.

public class ToUpperCaseBean implements ToUpperCaseRemote {

  public String toUpperCase(String s) {
    return s.toUpperCase();


This EJB session bean is running on the JBoss server (or any other JEE container).

I’m using the default Activiti-Spring integration, so I’m not going to describe the whole spring config here. Suffice to say I have my ProcessEngine configured as a Spring bean:

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="databaseType" value="h2" />
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />


I’m going to run the BPMN 2.0 example process in standard Java environment, so I need to access the EJB through its remote interface. I’m actually going to let Spring do all the hard work, by defining a Spring bean that’ll wrap all the dirty JNDI stuff for me:

<jee:remote-slsb id="toUpperCaseEjbBean" resource-ref="false"
		 jndi-name="ToUpperCaseBean/remote" />

The BPMN 2.0 process in which I’ll call the EJB is again as simple as possible, to make my point. I’m sure you can imagine more awesome scenario’s for it. Here, the process has a start, a call to the EJB, the output of the call (ie the uppercased String) and that’s it.

In BPMN 2.0 XML, this boils down to the following:

<process id="callEjbExample" name="Call EJB example">

    <startEvent id="theStart" />
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="callEjb" />

    <serviceTask id="callEjb"
                 activiti:resultVariableName="var" />
    <sequenceFlow id="flow2" sourceRef="callEjb" targetRef="outputResult" />

    <scriptTask id="outputResult" scriptFormat="groovy">
    		out:println "uppercased version = " + var
    <sequenceFlow id="flow3" sourceRef="outputResult" targetRef="theEnd" />

    <endEvent id="theEnd" />


For this tutorial, the serviceTask definition is the most interesting:

<serviceTask id="callEjb"
     activiti:resultVariableName="var" />

When process execution arrives at the serviceTask, it will execute the toUpperCaseEjbBean.toUpperCase(var) expression. The toUpperCaseEjbBean is actually our wrapped EJB as a Spring bean (see the Spring config above), on which we here invoke the toUpperCase method. This Activiti-Spring-expression integration is pretty cool, right? On the last line, you can see the result of executing the expression is stored in the var variable.

All that is left to do is execute this process on the Activiti engine:

// setup the Spring container and get the Activiti ProcessEngine bean from it
ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
ProcessEngine processEngine = context.getBean(ProcessEngine.class);

// Deploy process

// Run process
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("var", "Activiti, the rock-solid BPM engine");
processEngine.getRuntimeService().startProcessInstanceByKey("callEjbExample", variables);

Which spits out (of course) following console output:

And that’s all there is to it! If you want to try it for yourself, here are the sources, packaged as two Maven projects: one for the ejb and one for running the process.

Without Spring?

If you’ve taken a look at the sources, you’ll notice that getting the dependencies right isn’t trivial. Hell, 99% of my time went to figuring out which libraries I needed and why the hell asm was three times on my classpath with different versions.

In the next months, we’ll be adding a ‘native’ way of calling EJB’s in a BPMN 2.0 process, without having to go through Spring. That way, you’ll just need Activiti and we’ll take care of everything behind the scenes. However, the approach in this tutorial can be used for many other use cases: JMS, webservice calls, some legacy system, etc. Conclusion of this story: If you can wrap it in a Spring bean, you can use it in your BPMN 2.0 process.