AnsweredAssumed Answered

Spring bean not found in expressions (JavaConfig issue)

Question asked by ochrons on Apr 24, 2012
Latest reply on Apr 24, 2012 by ronald.van.kuijk
Thought I would post this issue and solution should someone else run into similar problem in the future…

I fought for many hours with a problem where Activiti would not be able to find Spring beans when used in expressions like

where the bean was defined as

public class ProcessingOrderTask {
    private static final Logger log = LoggerFactory.getLogger(ProcessingOrderTask.class);

    public void validateOrder(DelegateExecution execution) throws Exception {

I tried all kinds of tricks and solution suggestions that I could find in forums and even debugged through the expression evaluation code to understand what was wrong.

Finally I looked at Activiti code base and noticed that there was a SpringExpressionManager class that didn't show up in my expression evaluation phase. Turns out this was never instantiated due to missing applicationContext in the process engine factory.

The reason why it was missing is that I'm using Spring Java Config instead of XML config to initialize beans. ProcessEngineFactory indicates that it requires application context through implementing ApplicationContextAware interface, which is automatically called when the bean is created via XML definition. But not so when using Java Config!

I had to manually call setApplicationContext to get things working. Now the expressions are evaluated nicely.

Otto Chrons, CTO, Microtask Ltd.