cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti runtimeService in Spring context and in class that it's not Spring bean

bluelettuce16
Champ in-the-making
Champ in-the-making
Hi,

I am new to Activiti and I am very interested to master it Smiley Happy
I have the following problem. I am writing application that uses Spring container however not all my classes are Spring beans - part of them are just simple classes. I need the Activity runtimeService in both cases. My solution is that I have two configurations one for spring with annotations and second one which points to the same database in activity.cfg.xml.
My question is will it cause any troubles? For example is runtimeService the same in both cases?
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
You'll have 2 different engines created: one booted by the spring-container and one standalone. You'll have 2 separate datasources (each taking up X number of connections, in the worst case) and 2 job-executors who will be competing to execute jobs (which may lead to a tiny bit of overhead when doing optimistic locking).

Hence, you'll have 2 different instances of runtimeService - any difference in configuration *could* cause issues when engine 1 reads processes started by engine 2. Can't you create an additional bean that is AplicationContextAware (and perhaps listens for ApplicationContextEvents) which extract the process-engine from the spring-context and exposes this though a thread-local or static field?

frederikherema1
Star Contributor
Star Contributor
Which reminds me, the ProcessEngines class does exactly what you need. When spring boots the engine, it will be registered with the ProcessEngines object, available for non-spring aware services to fetch it in a static way…

bluelettuce16
Champ in-the-making
Champ in-the-making
I forgot to mention that I've used ProcessEngines.getDefaultProcessEngine(), so this is ok?

bluelettuce16
Champ in-the-making
Champ in-the-making
Thanks for the reply. I will try to use AplicationContextAware bean.