cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing spring beans from activiti-rest

joachimvda
Champ in-the-making
Champ in-the-making
How can I access my spring beans in the JUEL expressions for processes which are running in Activiti-REST (and accessible to the user using activiti-explorer).

I have already changed the activiti.cfg.xml to use SpringProcessEngineConfiguration insted of StandaloneProcessEngineConfiguration, but it seems my beans are still not accessible using an expression like ${myBean}.

I have tried defining my bean both in activiti.cfg.xml and web-application-context.xml, but it does not seem to make a difference.

I am using Activiti 5.4.

Thanks for your attention.

Joachim
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
Hi,

Currently, the rest-webapp uses the non-spring way of getting the process-engine (ProcessEngines.getProcessEngine(…)).
So the spring-context is loaded and only the processEngine bean is used.

If you want to use additional beans in activiti-rest (without checking out activiti code and building a spring-ized version of the activiti-rest) you can add the "beans" you want to expose in your expression in the configuration.

http://activiti.org/userguide/index.html#exposingConfigurationBeans -> this mentions all beans are exposed when using spring but when not using spring, just declare the ones you want, eg:

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
 
    <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="" />

    <propery name="beans">
        <map>
          <entry><key>cool</key><value ref="coolService" /></entry>
        </map>
    </property>

-> expression ${cool.invokeMethod('123')} will now work in rest

joachimvda
Champ in-the-making
Champ in-the-making
Thanks for the help Frank.
Though I am not sure that will do the trick as my bean didn't even get initialized when put in activiti.cfg.xml.

Anyway, I actually fixed it by patching the ActivitiWebScript and ActivitiStreamingWebScript classes to use a spring generated and injected process engine. It is working fine now. I will try to document what I did later today.

Kind regards,
Joachim

frederikherema1
Star Contributor
Star Contributor
Thanks!