cancel
Showing results for 
Search instead for 
Did you mean: 

Use global beans in a process without a Spring context

sruiz
Champ in-the-making
Champ in-the-making
I'm trying to use a bean inside a serviceTask. This bean should be a field and common to several service tasks.

I tried to insert the bean as a variable. But checking the exception, I find that I can not. It's not storable (the bean is not a persistent object or a primitive so the I supose that the process engine can not charge in memory).

Then, I've tried to insert the bean inside the activiti.cfg.xml unsuccessfully. There is no error when the process engine is loaded but the process engine can not find the bean when I use the service Task. Inspecting the source, ProcessEngineConfiguration only charge the process engine from the xml file.

I've read in the User Manual that it's possible to use beans with the help of Spring Context.
Shall I need ALWAYS to use Spring Context for the use of global beans in the process engine?
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
How are you injecting the bean?

Normally, when using the expression="${myBean}" construct, it should be possible.

sruiz
Champ in-the-making
Champ in-the-making
I want to test the process engine without Spring, so I'm using activiti.cfg.xml file for loading the ActivityRule processEngine.
How can I "attach" myBeam to this processEngine? I've used this xml file:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id="processEngineConfiguration"
  class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
  <property name="databaseType" value="h2"/>
  <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
  <property name="jdbcDriver" value="org.h2.Driver"/>
  <property name="jdbcUsername" value="sa"/>
  <property name="jdbcPassword" value=""/>
<!– Database configurations –>
  <property name="databaseSchemaUpdate" value="true"/>
<!– job executor configurations –>
  <property name="jobExecutorActivate" value="false"/>
<!– mail server configurations –>
  <property name="mailServerPort" value="5025"/>
</bean>

<bean id="myBean" class="com.simpleprocess.main.MyBean">
  <property name= "myProperty" value="Hello, world!"/>
</bean>
</beans>

Then, I test the following simple process:
ç<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn"
typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/test">

<process id="globalBeanTest">
<startEvent id="startAlone" />
  <sequenceFlow targetRef="service" sourceRef="startAlone"/>
<serviceTask id="service" name="Servicio Hola" activiti:expression="#{myBean.callMethod()}"/>
  <sequenceFlow targetRef="endFailure" sourceRef="service"/>
<endEvent id="endFailure"/>
</process>
</definitions>

Is it the right way?
No problem loading the xml config file. Error when process started.

jbarrez
Star Contributor
Star Contributor
No this is not the correct way.
The file you posted; is for configuring Activiti standalone. If you want to call a Spring bean in your process, you will need to configure the Activiti process engine as a Spring bean, in a full blown Spring config.

See my latest post for an example: http://www.jorambarrez.be/blog/2011/01/13/tutorial-call-an-ejb-in-a-bpmn-2-0-process-using-activiti-...

sruiz
Champ in-the-making
Champ in-the-making
From your blog:
Without Spring?

If you’ve taken a look at the sources, you’ll notice that getting the dependencies right isn’t trivial. Hell, 99% of my time went to figuring out which libraries I needed and why the hell asm was three times on my classpath with different versions.

In the next months, we’ll be adding a ‘native’ way of calling EJB’s in a BPMN 2.0 process, without having to go through Spring. That way, you’ll just need Activiti and we’ll take care of everything behind the scenes. However, the approach in this tutorial can be used for many other use cases: JMS, webservice calls, some legacy system, etc. Conclusion of this story: If you can wrap it in a Spring bean, you can use it in your BPMN 2.0 process.

I suppose that there is a JIRA about the ‘native’ way of calling EJB’s in a BPMN 2.0 process, without having to go through Spring..

Answer done. Thank you, Joram.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
The 'Native' way is http://jira.codehaus.org/browse/ACT-537

There is already a small patch attached to that issue that makes it possible to call local ejb's from expressions. Use something like:
name.method(param1, param2) where name is 'simple'like
where 'name' is simple. java:env/…. does  not work, myName does and myName/remote can be written as myName__local (double underscore). The params are variable names.

The 'full' option where you can also call remote beans will not be in the 5.2 release, but the 5.3 (I hope)

sruiz
Champ in-the-making
Champ in-the-making
Thanks, Ronald. I've voted your JIRA and I'm waiting until "full" option.

I'll use Spring. It is a good framework for working.

It's not critical feature but anyway it's interesting.
The only bad point is that I would like to make my tests with Activiti alone and I must use Spring for testing.