Using Shared Process Engine

In the last section of this tutorial we learn how to use a shared process engine.

Alternative Configuration: Using Shared Process Engine

So far, we explored how to set up an embedded process engine inside a web application using the Spring Framework. You can also use the Spring Framework to develop applications that use a shared process engine. As opposed to the embedded process engine, the shared process engine is controlled independently from an application and is started / stopped by the runtime container (like Apache Tomcat). This allows multiple applications (or a single modular application) to use the same process engine. You can also re-deploy individual applications independently from the process engine.

In order to configure the loanapproval-spring example to work with a shared process engine, you have to change three things:

Firstly, we need to set the scope of the Maven dependency of the camunda-engine dependency to provided. On the Camunda BPM platform the process engine library is provided as a shared library and does not need to be bundled with the application:

<dependency>
  <groupId>org.camunda.bpm</groupId>
  <artifactId>camunda-engine</artifactId>
  <scope>provided</scope>
</dependency>

Furthermore, you can delete the dependencies org.springframework:spring-jdbc, com.h2database:h2, and org.slf4j:slf4j-jdk14.

Secondly, create the folder META-INF in the src/main/resources directory and add a src/main/resources/META-INF/processes.xml file to your application.

<?xml version="1.0" encoding="UTF-8" ?>

<process-application
    xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <process-archive name="loan-approval">
    <process-engine>default</process-engine>
    <properties>
      <property name="isDeleteUponUndeploy">false</property>
      <property name="isScanForProcessDefinitions">true</property>
    </properties>
  </process-archive>

</process-application>

And thirdly, the applicationContext.xml file is adjusted so that the shared process engine is looked up and a SpringServletProcessApplication is bootstrapped:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context-2.5.xsd" >

  <!-- bind the process engine service as Spring Bean -->
  <bean name="processEngineService" class="org.camunda.bpm.BpmPlatform" factory-method="getProcessEngineService" />

  <!-- bind the default process engine as Spring Bean -->
  <bean name="processEngine" factory-bean="processEngineService" factory-method="getDefaultProcessEngine" />

  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>

  <!-- bootstrap the process application -->
  <bean id="processApplication" class="org.camunda.bpm.engine.spring.application.SpringServletProcessApplication" />

  <context:annotation-config />

  <bean id="calculateInterestService" class="org.camunda.bpm.getstarted.loanapproval.CalculateInterestService" />

</beans>

We also removed Starter bean declaration as we are going to use Tasklist to manualy start the process. If you prefer, you can also remove the class itself as it not used anymore.

After Maven build and redeploy, process definitions will be automatically deployed. Then you can go to Tasklist, login with demo/demo credentials, click on Start process and start the Loan approval process. You will see in Tomcat logfile:

Spring Bean invoked

Catch up: Get the Sources of Bonus.

Download as .zip or checkout the corresponding tag with Git.

You can checkout the current state from the GitHub repository.

If you have not cloned the repository yet, please execute the following command:

git clone https://github.com/camunda/camunda-get-started-spring.git

To checkout the current state of the process application please execute the following command:

git checkout -f Bonus
Or download as archive from here.

On this Page: