cancel
Showing results for 
Search instead for 
Did you mean: 

Spring bean access in tasks and muiltiple ProcessEngines

bwd
Champ in-the-making
Champ in-the-making
Hi,

We're taking the approach of running multiple ProcessEngines in a single app server (each with a DataSource pointing to a different database schema) to provide multi-tenant support in an application.  We need to spin up engines on demand as customers come in, so we can't pre-configure them beforehand in the Spring configuration files.

I'm now able to build the ProcessEngines programatically instead of through Spring configuration, but i'm now finding that the Spring beans that I was previously accessing in BPMN expressions are no longer available.

Example configuration:

   <userTask activiti:candidateUsers="${groupBean.getCandidateUsers(execution,'blah')}" …

Example output when test is run:

Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'groupBean'
   at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
   at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
   at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
        …

The error makes sense:  Spring can't inject the beans used in the expression as it isn't creating the ProcessEngine instance.

Question:  Is there another 'blessed' programatic way to make a ProcessEngine aware of such beans if the Spring approach is no longer available?

I looked through the Activiti source and found the following method on org.activiti.spring.ProcessEngineFactoryBean:

  public ProcessEngine getObject() throws Exception

The implementation of this makes the following call

      processEngineConfiguration.setExpressionManager(
        new SpringExpressionManager(applicationContext, processEngineConfiguration.getBeans()));

which looks like it might do the trick, but when I add this to my code that builds the ProcessEngine, it still can't see the beans.

FYI - I'm using Activiti 5.4.

Thanks,

bwd
2 REPLIES 2

bwd
Champ in-the-making
Champ in-the-making
Update:  I was able to resolve the issue by making the following call against the ProcessEngineConfiguration object:

      .setExpressionManager( new SpringExpressionManager( applicationContext, null ) );

I would still be interested in hearing if there's a better/preferred approach for accomplishing the same thing.

frederikherema1
Star Contributor
Star Contributor