@Bean
  public ProcessEngineFactoryBean processEngine() {
    ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();

    SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
    configuration.setTransactionManager(dataSourceTransactionManager());
    configuration.setDatabaseType("h2");
    configuration.setJobExecutorActivate(false);
    configuration.setDataSource(targetDataSource());
    configuration.setDatabaseSchemaUpdate(getDatabaseSchemaUpdate());
    processEngineFactoryBean.setProcessEngineConfiguration(configuration);
    return processEngineFactoryBean;
  }
  @Test
  public void testService() throws Exception {

    assertNotNull(runtimeService);
    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
  }
  /**
   * 显示图片
   *
   * @return
   */
  @RequestMapping(value = "/viewPic.do")
  public void viewPic(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("executionId") String executionId)
      throws Exception {
    ProcessInstance processInstance =
        runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    // 使用spring注入引擎请使用下面的这行代码
    Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration());

    InputStream imageStream =
        ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
      response.getOutputStream().write(b, 0, len);
    }
  }