cancel
Showing results for 
Search instead for 
Did you mean: 

Use of Spring service tasks from Activiti Explorer

mdaviot
Champ in-the-making
Champ in-the-making
Hi,

I had previously a question about the use of Spring beans in services tasks.

But actually I need to use these beans from the Activiti Explorer. The idea is to make a simple production followup GUI for the production team using Activiti Explorer so they can see processes in error and with a user task retry the service tasks which failed.

When I execute a service task implement with a Spring bean from Activiti Explorer, I get again this org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'myService' as in my previous post.

I had a look at the source code for StartProcessInstanceClickListener, and I see that runtimeService = ProcessEngines.getDefaultProcessEngine().getRuntimeService(); … exactly what would cause this problem as was said in the previous post.


So in short my questions :
- is it possible to use Spring beans to implement a service task triggered from the Activiti Explorer as it is currently ?
- If yes, what could go wrong in my case ? The code source is available here on dropbox.

Thanks and regards
Michel
11 REPLIES 11

frederikherema1
Star Contributor
Star Contributor
ProcessEngines.getDefaultProcessEngine() -> this will also work when the engine is wired in spring. Once ANY engine starts, it get's registered with the ProcessEngines object. The explorer-app engine has no explicit name set (/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml), so the default is used, effectively exposing it as the default.

So the engine obtained should be the correct one. Every bean you wire in applicationContext.xml, should be available in expressions…

mdaviot
Champ in-the-making
Champ in-the-making
Hi, thanks for having a look.

I understand that it should work then …

But when I start my project (mvn jetty:run-exploded), deploy the process definition and start the process from the explorer webapp, I always get the same error org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'myService'.

I have checked in target\ErrorMgt-1.0.0\WEB-INF\applicationContext.xml and my bean is defined with 
<bean id="myService" class="net.atos.cetelem.service.impl.DemoService" />

This is really a very simple project, I don't think I have done any fancy stuff with spring …

Any idea why I keep getting this exception ?

Thanks and regards
Michel

frederikherema1
Star Contributor
Star Contributor
Can you debug the code on tomcat? Can you try intercepting when the SpringExpressionManager is used (createElResolver) or when expressions are resolved (see Expression.getValue). When using spring, this code is executed when engine is created, adding a spring-aware expression-manager:



protected void initializeExpressionManager() {
    if (processEngineConfiguration.getExpressionManager() == null && applicationContext != null) {
      processEngineConfiguration.setExpressionManager(
          new SpringExpressionManager(applicationContext, processEngineConfiguration.getBeans()));
    }
  }

you should be able to see if the right expression-manager is used and if the bean is actually in the application-context…

mdaviot
Champ in-the-making
Champ in-the-making
I am using jetty but was able to debug nonetheless.

When the webapp loads, I see the code quoted above executed and the SpringExpressionManager is instanciated and associated with the SpringProcessEngineConfiguration. The SpringExpressionManager knows my bean.

The problem is that this SpringExpressionManager is never used when I start my process, its method createElResolver is never called.

frederikherema1
Star Contributor
Star Contributor
Do you see the ProcessEngineFactoryBean do it's magic when spring-context is created?


protected void initializeExpressionManager() {
    if (processEngineConfiguration.getExpressionManager() == null && applicationContext != null) {
      processEngineConfiguration.setExpressionManager(
          new SpringExpressionManager(applicationContext, processEngineConfiguration.getBeans()));
    }
  }

mdaviot
Champ in-the-making
Champ in-the-making
I don't know what you mean with the magic, but yes I am going though this code

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

mdaviot
Champ in-the-making
Champ in-the-making
Hi,

Any news on that ? Should I create a JIRA for this issue ?

The project team asked for this now 10 days ago, I would really like to be able to give them an answer by the end of the week if possible …

Thanks and regards
Michel

frederikherema1
Star Contributor
Star Contributor
Can you see what expression-manager is used than? Debug in org.activiti.engine.impl.el.ExpressionManager itself… If this is used, try figuring out where it is instantiated (debug constructor, e.g.)

mdaviot
Champ in-the-making
Champ in-the-making
Thanks to your reply, and with a lot of debug in Activiti initialization, I was able to identify the root cause of my issue.

I had both an activiti.cfg.xml in the WEB-INF/classes folder and an applicationContext.xml in WEB-INF folder. Because of the ContextLoaderListener defined in my web.xml, Spring would initialize Activiti using the applicationContext.xml configuration file.

But then when webapp-explorer initializes with Vaadin, in goes to ProcessEngines.init. I don't know if this is on purpose of it is a bug, but in my case the isInitialized flag was false and the ProcessEngine is initialized with initProcessEnginFromResource and activiti.cfg.xml.
This ProcessEngine is then used from the StartProcess button in the webapp, and it cannot use the mechanism of Spring injection of beans in Service Tasks (it uses the default ExpressionManager, not the SpringExpressionManager which was injected by applicationContext.xml).

I solved the issue in my case by removing the activiti.cfg.xml (which was put there by Maven when merging the standard activiti-explorer with my custom application).

So in short, be careful not to use applicationContext.xml and activiti.cfg.xml at the same time or you can get 2 different ProcessEngine instantiated.
The sample project to reproduce this is still on my dropbox

Regards
Michel