cancel
Showing results for 
Search instead for 
Did you mean: 

repositoryService is null?

xiegs2007
Champ in-the-making
Champ in-the-making
I'm test activiti58 integrate with Spring3.0.6,and after ref activiti58's example activiti-context.xml,and copy the runtime libs ,test libs to my Eclipse SpringMVC project.
1,here is my junit4 test,it successed.
public class Deploy {
   private static ApplicationContext ctx;
   private static ProcessEngine processEngine;
   private static RepositoryService repositoryService;
   private static RuntimeService runtimeService;
   private static TaskService taskService;
   private static HistoryService historyService;
   private static ManagementService managementService;
   
   @BeforeClass
   public static void setUpBeforeClass() throws Exception{
      try{
         ctx = new ClassPathXmlApplicationContext("activitiContext.xml");
         processEngine = (ProcessEngine)ctx.getBean("processEngine");
         repositoryService = (RepositoryService)ctx.getBean("repositoryService");
         runtimeService = (RuntimeService)ctx.getBean("runtimeService");
         taskService = (TaskService)ctx.getBean("taskService");
         historyService = (HistoryService)ctx.getBean("historyService");
         managementService = (ManagementService)ctx.getBean("managementService");
      }catch(RuntimeException e){
         e.printStackTrace();
      }
   }
   
   @Test
   public void OpenDatabase(){
      System.out.println("—start test—-");
      
      // assert bean no null
      assertNotNull(processEngine);
      assertNotNull(repositoryService);
      assertNotNull(runtimeService);
      assertNotNull(taskService);
      assertNotNull(historyService);
      assertNotNull(managementService);
      
      //use repositoryService deploy to DB
      //repositoryService.createDeployment().name("TestReport.bar")
      //   .addClasspathResource("com/xiegs/activity/test/bpmn20/TestReport.bpmn20.xml")
      //   .addClasspathResource("com/xiegs/activity/test/bpmn20/TestReport.png")
      //   .deploy();
      // get deployed processDefinition list
      List<ProcessDefinition> processDefinitions = repositoryService
            .createProcessDefinitionQuery().orderByProcessDefinitionKey()
            .asc().orderByProcessDefinitionVersion().desc().list();
      assertNotNull(processDefinitions);
      assertEquals(2, processDefinitions.size());
      
      //show definition.because singleResult() returned exception when morethan one result.
      //ProcessDefinition processDefinition = repositoryService
      //      .createProcessDefinitionQuery().processDefinitionKey("TestReport")
      //      .singleResult();
      ProcessDefinition processDefinition = processDefinitions.get(1);
      String processResourceName = processDefinition.getResourceName();
      String diagramResourceName = processDefinition.getDiagramResourceName();
      System.out.println("bpmn's name:" + processResourceName + ",diagram name:" + diagramResourceName);
      System.out.println("—- ");
      
      //start a instance
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestReport");
      assertNotNull(processInstance);
      System.out.println("—-instance started—");
   
      //query and exec task
      Task task = taskService.createTaskQuery().singleResult();
      assertEquals("fill report",task.getName());
      taskService.complete(task.getId());
      assertEquals(1,taskService.createTaskQuery().count());
      System.out.println("—-finished fill report task—–");
      
      //query and exec task again
      task = taskService.createTaskQuery().singleResult();
      assertEquals("manager sign",task.getName());
      taskService.complete(task.getId());
      assertEquals(0,taskService.createTaskQuery().count());
      System.out.println("——finished manager asign task—–");
      
      // now the instance is finished
      assertEquals(0,runtimeService.createProcessInstanceQuery().count());
      System.out.println("——instance finished—–");
   }
}
2,then, in my springMVC's controller,I write code:
public class HelloController implements Controller {

   /**
    * Logger for this class and subclasses
    */
   protected final Log logger = LogFactory.getLog(getClass());

   public ModelAndView handleRequest(HttpServletRequest request,
         HttpServletResponse arg1) throws Exception {
      // add two return parameters
      request.setAttribute("helloEntity01", "hello,xiegs2007");
      request.setAttribute("helloEntity02", "this is a httpRequest param");
      request.setAttribute("helloEntity03", "use ${} get the result");

      if(pe == null){
         logger.info("—-processInstance isn't established—–");
      }
      
      // deploy a processInstance
      if (repositoryService != null) {
         repositoryService
               .createDeployment()
               .name("Test-Report.bar")
               .addClasspathResource(
                     "main/resources/diagrams/TestReport.bpmn20.xml")
               .addClasspathResource(
                     "main/resources/diagrams/TestReport.png").deploy();
         // get deployed instance list
         List<ProcessDefinition> processDefinitions = repositoryService
               .createProcessDefinitionQuery()
               .orderByProcessDefinitionKey().asc()
               .orderByProcessDefinitionVersion().desc().list();
         request.setAttribute("processlist", processDefinitions);

         // display deployed processDefinition
         ProcessDefinition processDefinition = repositoryService
               .createProcessDefinitionQuery()
               .processDefinitionKey("TestReport").singleResult();
         request.setAttribute("processdefinition", processDefinition);

         // start a processInstance

         // query and exec first task

         // query and exec second task

         // ensure instance completed and is deleted
      }
      else{
         request.setAttribute("processlist", " ");
         request.setAttribute("processdefinition", " ");
      }

      return new ModelAndView("WEB-INF/page/hello.jsp");
   }

   @Autowired
   protected ProcessEngine pe;
   @Autowired
   protected RepositoryService repositoryService;
}

to be continued
5 REPLIES 5

xiegs2007
Champ in-the-making
Champ in-the-making
continue:
3,exception throw:
2011-12-12 00:27:09,140 DEBUG org.springframework.web.servlet.DispatcherServletSmiley SadDispatcherServlet.java:693)
- DispatcherServlet with name 'springMVC' processing GET request for [/ActivitySpringIT/hello.do]
2011-12-12 00:27:09,156 DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMappingSmiley SadAbstractUrlHandlerMapping.java:221)
- Mapping [/hello.do] to HandlerExecutionChain with handler [com.xiegs.activity.test.action.HelloController@1de7497] and 1 interceptor
2011-12-12 00:27:09,156 DEBUG org.springframework.web.servlet.DispatcherServletSmiley SadDispatcherServlet.java:769)
- Last-Modified value for [/ActivitySpringIT/hello.do] is: -1
2011-12-12 00:27:09,156  INFO com.xiegs.activity.test.action.HelloControllerSmiley SadHelloController.java:32)
- —-processInstance isn't established—–


please help me!

trademak
Star Contributor
Star Contributor
Wow that's a lot of console output that isn't very useful.
I don't see anything wrong in your logic, but is the RepositoryService defined as a Spring bean somewhere?

Best regards,

xiegs2007
Champ in-the-making
Champ in-the-making
thank you ! yes,I did it like spring example:


   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/activity?autoReconnect=true" />
    <property name="username" value="activity" />
    <property name="password" value="activity" />
     <property name="defaultAutoCommit" value="false" />
  </bean>
 
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>
 
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
   <property name="dataSource" ref="dataSource"/>
      <property name="persistenceXmlLocation">
          <value>classpath:custom-persistence.xml</value>
      </property>
   <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
     <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
    </bean>
   </property>
  </bean>
 
  <context:annotation-config />
  <tx:annotation-driven transaction-manager="transactionManager"/>
 
  <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="mailServerHost" value="localhost" />
    <property name="mailServerPort" value="5025" />
    <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
    <property name="jpaHandleTransaction" value="true" />
    <property name="jpaCloseEntityManager" value="true" />
    <property name="jobExecutorActivate" value="false" />
  </bean>
 
  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>
 
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  …..
  <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />

</beans>

use junit test it behavior very well,bat in springMVC's controller I use spring's autowired annotation ,
   @Autowired                                       // autowired annotation
   protected ProcessInstance processInstance;
   …..
   if(processInstance == null){
      logger.info("—-processInstance isn't established—–");
   }
I guess in here ,my controller's context changed ,and can't access Root Context.

xiegs2007
Champ in-the-making
Champ in-the-making
finally, I checked the springMVC-servlet.xml and fund that
  <context:annotation-config />
this line is forgot.
after appended this line ,the inject var repositoryService ,processEngine…all are available.
thank you trademak! and merry christmas for you !
                    —wish you happy from a chinese programer!

Hi, This is a very old post, but I am facing exactly same problem. I dont see which line you actually added that made it work.