cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the application context and classloader for a process engine

alexd1
Champ on-the-rise
Champ on-the-rise
Hi,

I am having an issue creating a process engine that can both see all of its classes and my beans in my application context. I noticed that the Spring process engine configuration is application context aware, but it doesn't have a way for me to set the class loader. On the other side, the org.activiti.engine.ProcessEngineConfiguration has a way for me to set the class loader, but no method I can find to set the application context for it to be able to see its delegate beans.

I have a reference to the classloader and the application context. I just have no idea how to set both.


Here's how I am creating the engine in java.
ProcessEngines.init();
ProcessEngine processEngine = ProcessEngineConfiguration
   .createStandaloneProcessEngineConfiguration()
   .setDataSource(dataSource)
   .setDatabaseSchemaUpdate("true")
   .setJobExecutorActivate(false)
   .setClassLoader(applicationContext.getClassLoader())
   .setTransactionsExternallyManaged(true)
   .buildProcessEngine();
ProcessEngines.registerProcessEngine(processEngine);
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Do you have a specific class loader then? Could you explain a bit more why you need that.

Best regards,

alexd1
Champ on-the-rise
Champ on-the-rise
I am using activiti in an application that manages several application contexts in a cloud. The application context's class loader is the one I want. I can set it using the method above, but I don't see a way to set an application context as well.

If I don't set the classloader, activiti can't find any of its classes. If I do set the class loader, I get property not found exceptions when activiti executes delegate expressions because it doesn't know any of the beans, so it looks like to me, all it needs is the application context once it has the right class loader.

alexd1
Champ on-the-rise
Champ on-the-rise
I'm using activiti 5.14

Here's how i'm initializing the process engine. I'm doing it this way to be able to set both the classloader & the application context. It doesn't look like it using the loader I set.

<java>
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();
  conf.setDataSource(dataSource);
  conf.setTransactionManager(transactionManager);
  conf.setDatabaseSchemaUpdate("true");
  conf.setJobExecutorActivate(false);
  conf.setClassLoader(applicationContext.getClassLoader());
  conf.setTransactionsExternallyManaged(true);
  ProcessEngineFactoryBean factorybean = new ProcessEngineFactoryBean();
  factorybean.setApplicationContext(applicationContext);
  factorybean.setProcessEngineConfiguration(conf);
 
  ProcessEngine processEngine = null;
  try {
   processEngine = factorybean.getObject();
  } catch (Exception e1) {
   logger.debug("Exception occurred while creating the process engine");
   e1.printStackTrace();
  }
  ProcessEngines.registerProcessEngine(processEngine);
</java>

<code>
org.activiti.engine.ActivitiException: Error while evaluating expression: #{kbaDelegate.execute(execution)}
        at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:59)
        at org.activiti.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior.execute(ServiceTaskExpressionActivityBehavior.java:45)
        at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
        at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListe
  …
Caused by: org.activiti.engine.impl.javax.el.ELException: Could not find expression factory class
        at org.activiti.engine.impl.javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:209)
        at org.activiti.engine.impl.javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:183)
        at org.activiti.engine.impl.javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:89)
        at org.activiti.engine.impl.javax.el.BeanELResolver.getExpressionFactory(BeanELResolver.java:527)
        at org.activiti.engine.impl.javax.el.BeanELResolver.invoke(BeanELResolver.java:479)
        at org.activiti.engine.impl.javax.el.CompositeELResolver.invoke(CompositeELResolver.java:397)
        at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:91)
        at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
        at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
        at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
        at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
        at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33)
        at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
        at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
        at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:50)
        … 212 more
Caused by: java.lang.ClassNotFoundException: org.activiti.engine.impl.juel.ExpressionFactoryImpl
        at org.grails.plugins.tomcat.ParentDelegatingClassLoader.findClass(ParentDelegatingClassLoader.java:59)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at org.activiti.engine.impl.javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:204)
        … 226 more
</code>

frederikherema1
Star Contributor
Star Contributor
Why do you need a custom class loader? Are you sure the activiti-engine is on that classloader's classpath?