AnsweredAssumed Answered

New Spring applicationContext started by activiti-rest

Question asked by engywook on Mar 27, 2013
Latest reply on Mar 29, 2013 by engywook
I have a Spring (3.2.2) managed web application using Activiti 5.12.  I'm not having any issues with this configuration and Activiti performs as expected.  The process engine is managed by Spring and has access to all the beans it needs.  We have not been using activiti-explorer or activiti-rest with this configuration.

Now I'm trying to incorporate the activiti-rest jar into the existing webapp.  I have the servlet mapping configured and am able to process certain requests that don't use other spring beans.  It looks like activiti-rest uses Activiti's ProcessEngines class to load an entirely new applicationContext based on activiti-context.xml, which results in a new process engine.  In my application, the activiti-context.xml file is one of many context files imported by the main application context XML file.  So this new application context does not have access to all of the beans nor to the camel context that some of the tasks delegate to. 

I figure I could restructure the context files so the rest context has the same beans, but I'd prefer to have one context and especially one camel context.  I've considered the possibility of just letting ProcessEngines start the application context and disabling the org.springframework.web.context.ContextLoaderListener but I have not tried that. 

I'm mainly looking for advice here.  What's the best way to include the activiti-rest jar in an existing spring application?  Is there a way to inject the process engine into activiti-rest's relelvant classes or to initialize ProcessEngines with Spring process engine rather than ProcessEngines creating its own application context and process engine? 


I'm not sure if this is useful but here's my web.xml.

   <display-name>webapp name</display-name>
      <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
   <!– activiti-rest –>
         <!– Application name –>

I altered my activiti-context.xml  to include all the datasource and transaction management beans so that ProcessEngines can start that new context, but I'm not importing everything here so some beans are still missing, particularly camel.

   <context:component-scan base-package=""/>
   <import resource="properties-context.xml" />
   <import resource="data-source-context.xml" />
   <import resource="persistence-context.xml" />
   <import resource="activiti-processEngine-context.xml" />

activiti-processEngine-context.xml is a new file what the main application context xml file imports now on application start.

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration" depends-on="entityManagerFactory">
      <property name="databaseType" value="${activiti.processEngineConfiguration.databaseType}" />
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="${activiti.processEngineConfiguration.databasechemaUpdate}" />
      <property name="deploymentResources" value="classpath*:processes/*.bpmn" />
      <property name="history" value="audit" />
      <property name="jobExecutorActivate" value="true" />
      <property name="customSessionFactories">
            <ref bean="ldapUserManagerFactory"/>
            <ref bean="ldapGroupManagerFactory"/>

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

   <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" />
   <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
   <bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
      <property name="processEngine" ref="processEngine" />
   <bean id="activitiRest" class=""/>