AnsweredAssumed Answered

Spring bean cannot be resolved in activiti:delegateExpression

Question asked by rohitjain on Oct 29, 2014
Latest reply on Oct 31, 2014 by jbarrez
I've this Java based spring configuration file:


@Configuration
public class WorkflowConfig {

   @Bean
   public DataSource activitiDataSource() {
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.setUrl("xxxx");
      dataSource.setUsername("xxxx");
      dataSource.setPassword("xxxx");
      return dataSource;
   }

   @Bean
   @DependsOn({ "activitiDataSource" })
   public PlatformTransactionManager txManager() {
      return new DataSourceTransactionManager(activitiDataSource());
   }

   @Bean
   @DependsOn({ "txManager" })
   public SpringProcessEngineConfiguration processEngineConfiguration() {
      SpringProcessEngineConfiguration processEngineConfig = new SpringProcessEngineConfiguration();
      processEngineConfig.setDataSource(activitiDataSource());
      processEngineConfig.setTransactionManager(txManager());
      processEngineConfig.setDatabaseSchemaUpdate("true");
      processEngineConfig.setDatabaseType("mysql");
      processEngineConfig.setJobExecutorActivate(true);
      processEngineConfig
            .setDeploymentResources(new ClassPathResource[] {
                           new ClassPathResource("invoiceWorkflow.bpmn")
                        });
      return processEngineConfig;
   }

   @Bean
   @DependsOn({ "processEngineConfiguration" })
   public ProcessEngine processEngine() {
      return processEngineConfiguration().buildProcessEngine();
   }

   @Bean
   public WorkflowService workflowService() {
      return new WorkflowService();
   }
   
   @Bean
   public FetchTicket fetchTicket() {
      return new FetchTicket();
   }
}


<blockcode>FetchTicket</blockcode> is my JavaDelegate class, as shown below:


public class FetchTicket implements JavaDelegate {

   @Autowired
   private TicketService ticketService;

   @Override
   public void execute(DelegateExecution execution) throws Exception {
            System.out.println(ticket);
   }
}


Since I've configured <blockcode>FetchTicket</blockcode> as a spring bean, I used it in expression as below in BPMN config file:


<definitions ….>
<process id="invoiceGenerationProcess" name="Invoice Generation Process"
      isExecutable="true">
      <startEvent id="start" name="Start" />
      <serviceTask id="showTickets" name="Show Tickets"
         activiti:delegateExpression="${fetchTicket}" />
      <sequenceFlow id="flow1" sourceRef="start" targetRef="showTickets" />
      <userTask id="generateInvoice" name="Generate Invoice" />
      <sequenceFlow id="flow2" sourceRef="showTickets"
         targetRef="generateInvoice" />
      <endEvent id="endevent1" name="End" />
      <sequenceFlow id="flow3" sourceRef="generateInvoice"
         targetRef="endevent1" />
   </process>
</definitions>


But the expression: <blockcode>${fetchTicket}</blockcode> is not getting resolved. I see that bean <blockcode>fetchTicket</blockcode> is created clearly in the logs:

<blockcode>
00:26:28.017 [main] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'fetchTicket' to bean named 'ticketService'
00:26:28.017 [main] DEBUG o.s.c.a.CommonAnnotationBeanPostProcessor - Invoking init method on bean 'fetchTicket': public void com.redbus.activiti.servicetask.FetchTicket.afterPropertiesSet()
Ticket Service: com.redbus.service.impl.TicketServiceImpl@576e18c5
00:26:28.018 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'fetchTicket'
</blockcode>

Can you please help me out of this? And also it would be great if you can review, if my Activiti spring config is fine? I converted it to java based from the XML.

Outcomes