Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Spring Beans in Activiti JavaDelegate tasks

I am using activiti 5.16.1 to enable workflow in my project.

I have a spring beans which carry out business task such as populating data from database for a given id.

When I try to use these beans in JavaDelegate task, these beans are not populated.

@Component
public class ServiceClassDelegateSample implements JavaDelegate {

    @Autowired
    private SampleService sampleService;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {

        sampleService.doSomeTask();
    }

}

However sampleService is always set to null.

Are you aware of how to use spring beans in JavaDelegate task?

There is similar question here without any proper solution and I hope there is better way in newer version of Activiti.

like image 919
palkars Avatar asked Dec 19 '22 11:12

palkars


1 Answers

If I remember correctly, it is some kind of glitch in Activiti, but you can easily solve it if you replace

<serviceTask id="servicetask" name="Service Task" activiti:class="some.class.path.ServiceClassDelegateSample"></serviceTask>

with delegate expression;

<serviceTask id="serviceTask" activiti:delegateExpression="${serviceClassDelegateSample}"></serviceTask>

where serviceClassDelegateSample is a name of your bean.

But why doesn't work in first way, I don't know.

like image 189
Petar Butkovic Avatar answered Mar 16 '23 02:03

Petar Butkovic