Bootstrap Application-Managed Process Engine with EJB: process engine 'default' no such process engine exists

Hi, I’m trying to add an embedded (application-managed) process engine to an existing EJB application.

According to the logs the process engine “default” has been created, however, when trying to deploy a process archive, the engine “default” is reported to not exist.

To create the process engine I’m calling ProcessEngines.init() on startup and to deploy my process application I’m subclassing EmbeddedProcessApplication and calling deploy() on it during startup.

I’m stuck. Can somebody help me?

15-Jul-2019 10:32:22.208 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-00003 Initializing process engine for resource file:/Users/username/Documents/my-app/target/apache-tomee/webapps/montigem-be/WEB-INF/classes/camunda.cfg.xml
15-Jul-2019 10:32:22.370 INFO [localhost-startStop-1] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from resource loaded through InputStream
15-Jul-2019 10:32:26.335 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql'
15-Jul-2019 10:32:26.377 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.history.sql'
15-Jul-2019 10:32:26.392 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'identity' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.identity.sql'
15-Jul-2019 10:32:26.408 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'case.engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.case.engine.sql'
15-Jul-2019 10:32:26.413 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'case.history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.case.history.sql'
15-Jul-2019 10:32:26.420 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'decision.engine' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql'
15-Jul-2019 10:32:26.431 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03016 Performing database operation 'create' on component 'decision.history' with resource 'org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql'
15-Jul-2019 10:32:26.460 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03067 No history level property found in database
15-Jul-2019 10:32:26.460 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-03065 Creating historyLevel property in database for level: HistoryLevelAudit(name=audit, id=2)
15-Jul-2019 10:32:26.523 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-00001 Process Engine default created.
15-Jul-2019 10:32:26.536 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-00004 Initializing process engine default
15-Jul-2019 10:32:31.338 INFO [localhost-startStop-1] org.camunda.commons.logging.BaseLogger.logInfo ENGINE-08024 Found processes.xml file at file:/Users/username/Documents/my-app/target/apache-tomee/webapps/montigem-be/WEB-INF/classes/META-INF/processes.xml
15-Jul-2019 10:32:31.351 SEVERE [localhost-startStop-1] org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException EjbTransactionUtil.handleSystemException: ENGINE-08043 Exception while performing 'Deployment of Process Application process-app' => 'Deployment of process archive 'loan-approval': Cannot deploy process archive 'loan-approval' to process engine 'default' no such process engine exists: processEngine is null
 org.camunda.bpm.engine.ProcessEngineException: ENGINE-08043 Exception while performing 'Deployment of Process Application process-app' => 'Deployment of process archive 'loan-approval': Cannot deploy process archive 'loan-approval' to process engine 'default' no such process engine exists: processEngine is null

MyProcessApplication.java:

package mypackage;

import org.camunda.bpm.application.ProcessApplication;
import org.camunda.bpm.application.impl.EmbeddedProcessApplication;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.DependsOn;
import javax.ejb.Singleton;
import javax.ejb.Startup;

@Singleton
@Startup
@DependsOn("ProcessEngineStartup")
@ProcessApplication("process-app")
public class MyProcessApplication extends EmbeddedProcessApplication {

    @PostConstruct
    public void start() {
        deploy();
    }

    @PreDestroy
    public void stop() {
        undeploy();
    }

}

ProcessEngineStartup.java:

package mypackage;

import org.camunda.bpm.engine.ProcessEngines;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;

@Singleton
@Startup
public class ProcessEngineStartup {

    @PostConstruct
    public void start() {
        ProcessEngines.init();
    }

    @PreDestroy
    public void stop() {
        ProcessEngines.destroy();
    }

}

resources/camunda.cfg.xml:

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

    <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">

        <property name="jdbcUrl" value="jdbc:h2:mem:camunda;DB_CLOSE_DELAY=1000" />
        <property name="jdbcDriver" value="org.h2.Driver" />
        <property name="jdbcUsername" value="sa" />
        <property name="jdbcPassword" value="" />

        <property name="databaseSchemaUpdate" value="true" />

        <property name="jobExecutorActivate" value="false" />

        <!-- <property name="mailServerHost" value="mail.my-corp.com" /> -->
        <!-- <property name="mailServerPort" value="5025" /> -->
    </bean>

</beans>

resources/META-INF/processes.xml:

<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>

loan-approval.bpmn is also located in /resources