Factory-bean 'processEngine' returned null

I am trying to configure shared process engine for my new application running in Tomcat. The engine is started with bpm-platform.xml file placed in Tomcat conf folder.

The engine is starting successfully and I am able to see the below message in logs:

Camunda BPM platform sucessfully started at ‘Apache Tomcat/8.0.24’.

But then while trying to deploy the application on server,I get the following error.

16-Feb-2019 05:37:38.331 SEVERE [main] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘repositoryService’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: factory-bean ‘processEngine’ returned null

Basically,I am trying to replicate this exercise.

Please advise.pom.xml (1.9 KB)

Hi,

Your pom.xml looks good.
Could you please share your applicationContext.xml and the initialization of repositoryService, I assume is in the Starter class of the exercise.

also here is more recent version of the guide:
https://docs.camunda.org/get-started/spring/service-task/

Hi Yana,

Thanks for responding. PFB the requested files.

applicationContext.xml (2.7 KB)
Starter.txt (1.1 KB)

Ok I will check this.

The repositoryService is not initialized in Starter and I assume that you’re using it in AllRunningProcessInstances so you just need to define it similar to runtimeService:

public class Starter implements InitializingBean {

  @Autowired
  private RuntimeService runtimeService;

  @Autowired
  private RepositoryService repositoryService;

  //...

  public void setRuntimeService(RuntimeService runtimeService) {
    this.runtimeService = runtimeService;
  }

  public void setRepositoryService(RepositoryService repositoryService) {
    this.repositoryService = repositoryService;
  }
}

Thanks Yana,that’s a good point.I implemented the same but now I get a different error even though I implemented JavaDelegate for AllRunningProcessInstances service.

19-Feb-2019 08:49:12.327 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.camunda.bpm.getstarted.loanapproval.Starter#0’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.camunda.bpm.engine.ProcessEngineException: Delegate expression {allRunningProcessInstances} did neither resolve to an implementation of interface org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior nor interface org.camunda.bpm.engine.delegate.JavaDelegate

Could you please share AllRunningProcessInstances.

PFB

AllRunningProcessInstances.txt (1.8 KB)

Here is how to access process engine service via delegation code:
https://docs.camunda.org/manual/7.10/user-guide/process-engine/delegation-code/#access-process-engine-services

Hi Yana,

I followed all the correct steps but still getting same error.Your advice will be greatly appreciated.

19-Feb-2019 18:31:04.171 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.camunda.bpm.engine.impl.interceptor.CommandContext.close Error while closing command context
org.camunda.bpm.engine.ProcessEngineException: Delegate expression {allRunningProcessInstances} did neither resolve to an implementation of interface org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior nor interface org.camunda.bpm.engine.delegate.JavaDelegate

Thanks

Hi Yana,

I resolved the above issue and it was due to a missing “$” while defining the delegate expression in bpmn diagram.

But,when I execute the below code.

package org.camunda.bpm.getstarted.loanapproval;

import org.camunda.bpm.BpmPlatform;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class AllRunningProcessInstances implements JavaDelegate {

public void execute(DelegateExecution execution) throws Exception {
	
	System.out.println("AllRunningProcessInstances Bean invoked now");
	// TODO Auto-generated method stub
	// get process engine and services
	
	ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
	RuntimeService runtimeService = processEngine.getRuntimeService();
}

}

I get the error:

20-Feb-2019 11:35:31.139 SEVERE [main] org.camunda.bpm.engine.impl.interceptor.CommandContext.close Error while closing command context
java.lang.NullPointerException
at org.camunda.bpm.getstarted.loanapproval.AllRunningProcessInstances.execute(AllRunningProcessInstances.java:25)

so looks like,the “processEngine” variable is null.Am I missing any configuration.

Hi,

Please see my last comment.
You are not fetching the runtimeService correctly in the delegation code.