AnsweredAssumed Answered

@Autowired private RuntimeService runtimeService; is giving null

Question asked by logicallimit on Apr 29, 2016
Latest reply on May 2, 2016 by logicallimit
I am trying to build a spring web mvc application using Activiti 5.19.0.2.

When I try to call Activiti API from a java class  where I use @Autowired to get instance of activity engine, I am getting null. Am I missing something in my following code.

mvc-dispatcher-servlet.xml

<!– Activiti related beans–>
   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
      <property name="enableDatabaseEventLogging" value="true" />
      <!– <property name="customFormTypes">
         <list>
            <bean class="org.activiti.explorer.form.UserFormType" />
            <bean class="org.activiti.explorer.form.ProcessDefinitionFormType" />
            <bean class="org.activiti.explorer.form.MonthFormType" />
         </list>
      </property> –>
      
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="formService" factory-bean="processEngine"
      factory-method="getFormService" />
   <bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" />
   <bean id="managementService" factory-bean="processEngine"
      factory-method="getManagementService" />
   <bean id="identityService" factory-bean="processEngine"
      factory-method="getIdentityService" />


And following is my java class code:


   @Autowired
   private RuntimeService runtimeService;
   
   @Autowired
   private RepositoryService repositoryService;
   
   public void startProcess(EmEntity emEntity){
      
      repositoryService.createDeployment().name("Em Test").addInputStream("em-test.bpmn20.xml", ReflectUtil.getResourceAsStream("diagrams/em-test.bpmn")).deploy();
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("em-test");
      runtimeService.setVariable(processInstance.getId(), "emitraEntity", emitraEntity);
   }


In above java code both "runtimeService" and "repositoryService" are null.

Outcomes