2 u013465293 u013465293 于 2017.09.07 17:16 提问

spring+activiti 注入servici问题 1C

测试调用空指针异常。断点查看,自己封装的方法ActivitiInter,repositoryService为null
应该是说明这个repositoryService没有注入进来。
具体哪出的问题呢?

以下为配置和代码

application.xml中Activiti配置

    <property name="dataSource" ref="dataSource" />

    <property name="transactionManager" ref="transactionManager" />

    <property name="databaseSchemaUpdate" value="true" />
</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="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />







Activiti服务封装的接口:



package com.ln.web.activiti;

import java.util.List;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;

/**

  • Activiti服务接口
  • @author linan
    *
    */
    public class ActivitiInter {

    @Autowired
    RepositoryService repositoryService;//获得activiti服务
    @Autowired
    RuntimeService runtimeService;//用于管理运行时流程实例
    @Autowired
    TaskService taskService;//用于管理运行时任务
    @Autowired
    FormService formService;
    @Autowired
    HistoryService historyService;

    /**

    • activiti服务列表
    • @return
      */
      public List activitiListByprocesskey(String process_key){

      List procDefList = repositoryService.createProcessDefinitionQuery()
      .processDefinitionKey(process_key)
      .orderByProcessDefinitionVersion()
      .desc()
      .list();

      return procDefList;
      }

    /**

    • 流程实例列表
    • @return
      */
      public List listProcInstByPdfid(String pdfid){

      List procInstList = runtimeService.createProcessInstanceQuery()
      .processDefinitionId(pdfid)
      .list();

      return procInstList;
      }

    /**

    • 当前任务的执行情况
    • @return
      */
      public List listExecutionByProId(String processInstanceId) {

      List exectionList = runtimeService.createExecutionQuery()
      .processInstanceId(processInstanceId)
      .list();

      return exectionList;
      }

    /**

    • 部署流程
    • @return
      */
      public Deployment deployProcDefByPath( String xmlPath){

      Deployment deploy = repositoryService.createDeployment()
      .addClasspathResource(xmlPath)
      .deploy();

      return deploy;
      }

    /**

    • 删除部署的流程
    • @param process_key */ public void deleteProcDefByprocesskey(String process_key){ List procDefList = this.activitiListByprocesskey(process_key); for(ProcessDefinition task : procDefList){ List tasks = taskService.createTaskQuery().processDefinitionId(task.getId()).list(); for(Task t : tasks){ taskService.deleteTask(t.getId()); }
      repositoryService.deleteDeployment(task.getDeploymentId()); } }

    /**

    • 启动流程
    • @param key
    • @return */ public ProcessInstance startProcessInstanceByKey(String key){ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key); return processInstance; }

    public RepositoryService getRepositoryService() {
    return repositoryService;
    }

    public void setRepositoryService(RepositoryService repositoryService) {
    this.repositoryService = repositoryService;
    }

    public RuntimeService getRuntimeService() {
    return runtimeService;
    }

    public void setRuntimeService(RuntimeService runtimeService) {
    this.runtimeService = runtimeService;
    }

    public TaskService getTaskService() {
    return taskService;
    }

    public void setTaskService(TaskService taskService) {
    this.taskService = taskService;
    }

    public FormService getFormService() {
    return formService;
    }

    public void setFormService(FormService formService) {
    this.formService = formService;
    }

    public HistoryService getHistoryService() {
    return historyService;
    }

    public void setHistoryService(HistoryService historyService) {
    this.historyService = historyService;
    }
    }

测试调用:
package com.ln.web.controller;

import org.activiti.engine.repository.Deployment;
import org.junit.Test;

import com.ln.web.activiti.ActivitiInter;

public class ActivitiTest2 extends TestBase{

@Test
public void eployment(){
    ActivitiInter act=new ActivitiInter();
    act.deployProcDefByPath("bpmn/MyProcess.bpmn");
    act.startProcessInstanceByKey("myProcess");
}

}

Csdn user default icon
上传中...
上传图片
插入图片