Using Spring Beans

Showing results for 
Search instead for 
Did you mean: 
Member II

Using Spring Beans

Hi all,

I'm fairly new to Activiti so apologies if this is basic.

I have a class implementing the JavaDelegate interface, but it also has an @Autowired bean inside it (it is a class annotated with @Service). I read that since I am autowiring, you can't specify it as an activiti:class inside the service task, you have to bind it using activiti:delegateExpression.

I have my implemented class as:

class MyDelegate implements JavaDelegate {
    MyCustomService myCustomService;


and I have defined the service task as:

<serviceTask id="servicetask1" name="Service Task 1" activiti:delegateExpression="${myDelegate}"></serviceTask>

However when I go to run the process, I get a runtime error saying:

org.activiti.engine.ActivitiException: Unknown property used in expression: ${myDelegate}

Is there something else I need to do?

If possible, I was hoping there was a solution that only used annotations rather than .xml bean definitions

1 Reply
Member II

Re: Using Spring Beans

The reason it didn't work it because I didn't set up my process engine correctly. The following got it working for me:

public class ProcessEngineConfig {
     private Resource resources[];

     public DataSource dataSource() {
          SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
          return dataSource;

     public PlatformTransactionManager transactionManager(DataSource dataSource) {
          DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
          return transactionManager;

     public SpringProcessEngineConfiguration processEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) {
          SpringProcessEngineConfiguration engineConfiguration = new SpringProcessEngineConfiguration();
          return engineConfiguration;

     public ProcessEngineFactoryBean processEngine(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
          ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
          return processEngineFactoryBean;

     public RepositoryService repositoryService(ProcessEngine processEngine) {
          return processEngine.getRepositoryService();

     public RuntimeService runtimeService(ProcessEngine processEngine) {
          return processEngine.getRuntimeService();

     public HistoryService historyService(ProcessEngine processEngine) {
          return processEngine.getHistoryService();

     public ManagementService managementService(ProcessEngine processEngine) {
          return processEngine.getManagementService();

     public TaskService taskService(ProcessEngine processEngine) {
          return processEngine.getTaskService();