cancel
Showing results for 
Search instead for 
Did you mean: 

issue with bean acces in service task

mdaviot
Champ in-the-making
Champ in-the-making
Hello,

I have been stuck all day with this issue… your help would be really welcome.

I have a simple process DemoErrorManagement with a service task implemented as an expression which refers to a bean : myService, speficied with the interface Service1.

In my unit test I inject the bean myService which is mocked by Mockito, it runs seamlessly.

From a main class (StartProcess) I use a slightly different activiti.cfg.xml file to inject the real bean : DemoService. But it is not found by Activiti :  org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'myService'
I checked by changing the activiti.cfg.xml file that it is really used.

I attach the full project (it is very small, only to reproduce the issue) : http://dl.dropbox.com/u/21035474/DemoErrorMgt.zip (no way to upload it here as attachment to the post ?)

Is it a bug in Activiti or what am I doing wrong ?

Thanks a lot
Michel
10 REPLIES 10

frederikherema1
Star Contributor
Star Contributor
I see you're using the SpringProcessEngineCOnfiguration. So the full spring-context is available to use in your expressions. So "myService" should just work.

Can you try adding the bean to the "beans" property in activiti configuration;


<property name="myService">
    <map>
      <entry key="myService" value-ref="myService" />
    </map>
  </property>

mdaviot
Champ in-the-making
Champ in-the-making
Hi and thanks for looking into this.

I'm really not a spring expert …  I tried to add this property under beans element

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http://www.springframework.org/schema/beans':import, "http://www.springframework.org/schema/beans':alias, "http://www.springframework.org/schema/beans':bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans':beans}' is expected.

and under bean  id="processEngineConfiguration" –>

org.springframework.beans.NotWritablePropertyException: Invalid property 'myService' of bean class [org.activiti.spring.SpringProcessEngineConfiguration]:
Where should I define this property ? And should it be defined for any bean I want to use from service tasks ?

Regards,
Michel

frederikherema1
Star Contributor
Star Contributor
whoops.. should have been "beans" under "processEngineConfiguration":


<property name="beans">
    <map>
      <entry key="myService" value-ref="myService" />
    </map>
  </property>

mdaviot
Champ in-the-making
Champ in-the-making
OK, this time the spring configuration is recognized, but it does not solve my issue at all.


<bean id="myService" class="net.atos.cetelem.service.impl.DemoService" />

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="history" value="full" />
  <property name="dataSource" ref="activitiDataSource" />
  <property name="transactionManager" ref="activitiTransactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />
 
  <property name="beans">
  <map>
   <entry key="myService" value-ref="myService" />
  </map>
</property>
</bean>

Would you try to reproduce it on your environment ? You just have to launch net.atos.cetelem.StartProcess, it uses an H2 DB.

org.activiti.engine.ActivitiException: Unknown property used in expression
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:55)

Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'myService'
at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)

frederikherema1
Star Contributor
Star Contributor
There is no file attached to your comment, please upload it somewhere on the web instead…

mdaviot
Champ in-the-making
Champ in-the-making
Project is available here : http://dl.dropbox.com/u/21035474/DemoErrorMgt.zip (as stated in the first post)

frederikherema1
Star Contributor
Star Contributor
I see your problem now, it's the way you fetch your process-engine. You're using "ProcessEngines.getDefaultProcessEngine()", this will only read the "processEngines" bean from the activiti.cfg.xml-file.

If you want to use spring, you have to:
  • Use org.activiti.spring.SpringProcessEngineConfiguration (which you are doing, so that's fine)

  • Create the ApplicationContext yourself (e.g.. by using Spring's servletContextListener or by creating a XMLClassPathApplicationContext)

  • Retreive the bean "processEngine" manually and use this INSTEAD of ProcessEngines.getDefaultProcessEngine()

mdaviot
Champ in-the-making
Champ in-the-making
Thanks a lot, you solved the issue for me !!

For the record, here is the working code if anyone is interested :


public class StartProcess {

  private static final ApplicationContext ac=
          new ClassPathXmlApplicationContext("activiti.cfg.xml");

static ProcessEngine processEngine = ac.getBean(ProcessEngine.class);

public static void main(String[] args) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  repositoryService.createDeployment().addClasspathResource("diagrams/DemoErrorManagement.bpmn20.xml").deploy();
  processEngine.getRuntimeService().startProcessInstanceByKey("DemoErrorManagement");

}

}

mdaviot
Champ in-the-making
Champ in-the-making
Note : this step is not required at all.

whoops.. should have been "beans" under "processEngineConfiguration":


<property name="beans">
    <map>
      <entry key="myService" value-ref="myService" />
    </map>
  </property>