3

我正在尝试使用 Activiti 5.13 BPMN 制作一个简单的 Hello world 应用程序。我在 Eclipse 中创建了一个动态 Web 应用程序项目,并将我的 hello_world.bpmn 图添加到根文件夹,并将我的 test.java 和 activiti.cfg.xml 文件添加到 src 文件夹。该应用程序只是假设将“Hello,world”打印到控制台,但我似乎无法让它这样做。下面如果我用来运行应用程序的所有文件,我也在使用 PostgreSQL 数据库(我创建了所有必要的表)

我的 hello_world.bpmn 文件如下:

开始事件 -> 用户脚本(groovy) -> 结束事件

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startProcess" name="Start"></startEvent>
    <scriptTask id="scriptProcess" name="Hello world" scriptFormat="groovy" activiti:autoStoreVariables="true">
      <script>System.out.println("Hello, world this is the activiti process")</script>
    </scriptTask>
    <endEvent id="endProcess" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startProcess" targetRef="scriptProcess"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="scriptProcess" targetRef="endProcess"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startProcess" id="BPMNShape_startProcess">
        <omgdc:Bounds height="35.0" width="35.0" x="110.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scriptProcess" id="BPMNShape_scriptProcess">
        <omgdc:Bounds height="55.0" width="105.0" x="210.0" y="210.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endProcess" id="BPMNShape_endProcess">
        <omgdc:Bounds height="35.0" width="35.0" x="390.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="145.0" y="237.0"></omgdi:waypoint>
        <omgdi:waypoint x="210.0" y="237.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="315.0" y="237.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="237.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

我的 activiti.cfg.xml 文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans ;
   http://www.springframework.org/schema/beans/spring-beans.xsd">
 <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
 <!-- Database configurations  -->
 <property name="databaseType" value="postgres" />
 <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/postgres" />
 <property name="jdbcDriver" value="org.postgresql.Driver" />
 <property name="jdbcUsername" value="user1234" />
 <property name="jdbcPassword" value="password1234" />
 </bean>
</beans>

我的 test.java 文件如下:

public class test {
    public static void main(String[] args) {

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RuntimeService runtimeService = processEngine.getRuntimeService();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        TaskService taskService = processEngine.getTaskService();
        ManagementService managementService = processEngine.getManagementService();
        IdentityService identityService = processEngine.getIdentityService();
        HistoryService historyService = processEngine.getHistoryService();
        FormService formService = processEngine.getFormService();

        runtimeService.startProcessInstanceByKey("myProcess");


        System.out.println("PRINT THIS MESSAGE");
    }
}

当我在我的 tomcat 服务器上运行应用程序时,我得到以下结果:

    11:34:14,359 [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader  - Root WebApplicationContext: initialization started
11:34:14,578 [localhost-startStop-1] INFO  org.springframework.web.context.support.XmlWebApplicationContext  - Refreshing Root WebApplicationContext: startup date [Wed Aug 21 11:34:14 CDT 2013]; root of context hierarchy
11:34:14,750 [localhost-startStop-1] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
11:34:14,890 [localhost-startStop-1] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/activiti-standalone-context.xml]
11:34:14,953 [localhost-startStop-1] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from ServletContext resource [/WEB-INF/activiti-ui-context.xml]
11:34:15,328 [localhost-startStop-1] INFO  org.springframework.beans.factory.config.PropertyPlaceholderConfigurer  - Loading properties file from class path resource [db.properties]
11:34:15,343 [localhost-startStop-1] INFO  org.springframework.beans.factory.config.PropertyPlaceholderConfigurer  - Loading properties file from class path resource [ui.properties]
11:34:15,437 [localhost-startStop-1] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory  - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@caa278: defining beans [demoDataGenerator,dbProperties,dataSource,transactionManager,processEngineConfiguration,processEngine,repositoryService,runtimeService,taskService,historyService,managementService,identityService,activitiLoginHandler,activitiUiPropertyPlaceholder,navigatorManager,attachmentRendererManager,formPropertyRendererManager,variableRendererManager,componentFactories,processDefinitionFilterFactory,deploymentFilterFactory,navigationFragmentChangeListener,mainWindow,explorerApp,i18nManager,scopedTarget.messageSource,messageSource,notificationManager,viewManager,workflowDefinitionConversionFactory]; root of factory hierarchy
11:34:19,531 [localhost-startStop-1] INFO  org.activiti.engine.impl.ProcessEngineImpl  - ProcessEngine default created
11:34:19,531 [localhost-startStop-1] INFO  org.activiti.engine.impl.jobexecutor.JobExecutor  - Starting up the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].
11:34:19,531 [Thread-1] INFO  org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable  - JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs
11:34:19,546 [localhost-startStop-1] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Initializing demo groups
11:34:19,765 [localhost-startStop-1] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Initializing demo users
11:34:19,921 [localhost-startStop-1] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Initializing demo process definitions
11:34:19,937 [localhost-startStop-1] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Initializing demo models
11:34:19,953 [localhost-startStop-1] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Initializing demo report data
11:34:19,953 [Thread-2] INFO  org.activiti.engine.impl.jobexecutor.JobExecutor  - Shutting down the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].
11:34:19,953 [Thread-1] INFO  org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable  - JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] stopped job acquisition
11:34:20,281 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/VacationRequest.png
11:34:20,281 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/FixSystemFailureProcess.bpmn20.xml
11:34:20,484 [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader  - Root WebApplicationContext: initialization completed in 6109 ms
Aug 21, 2013 11:34:20 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 21, 2013 11:34:20 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Aug 21, 2013 11:34:20 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15043 ms
11:34:21,250 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/FixSystemFailureProcess.png
11:34:21,250 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/VacationRequest.bpmn20.xml
11:34:21,421 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/createTimersProcess.bpmn20.xml
11:34:21,484 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/simple-approval.simpleApprovalProcess.png
11:34:21,484 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/reviewSalesLead.bpmn20.xml
11:34:21,593 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/reviewSalesLead.reviewSaledLead.png
11:34:21,593 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/Helpdesk.png
11:34:21,593 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/Helpdesk.bpmn20.xml
11:34:21,656 [Thread-2] INFO  org.activiti.engine.impl.bpmn.deployer.BpmnDeployer  - Processing resource org/activiti/explorer/demo/process/simple-approval.bpmn20.xml
11:34:36,953 [Thread-2] INFO  org.activiti.engine.impl.jobexecutor.JobExecutor  - Starting up the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].
11:34:36,953 [Thread-2] INFO  org.activiti.explorer.demo.DemoDataGenerator  - Demo report data generated
11:34:36,953 [Thread-4] INFO  org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable  - JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs
4

3 回答 3

1

这里的东西看起来不错。您是否查看过 activiti explorer 以确保您的流程正确部署?您也可以在资源管理器中练习您的流程。在您开始在代码中使用它之前,这可以作为一个健全性检查。

那个进程名称看起来有点滑稽。通常,当您通过资源管理器将流程部署到 activiti 时,它会在流程名称后附加一个版本号,例如“myProcess:23”。这个扩展名称是您用来实例化进程的名称。

于 2013-08-21T19:35:43.570 回答
1

这段代码是完全错误的。要测试您的过程,请查看文档的这一 章,或者按照 Hethcox 的建议使用 Activiti Explorer。如果您想在 Web 应用程序章节中更正现有的应用程序读取流程引擎

于 2013-08-22T15:19:31.413 回答
1

我已经写了一篇非常详细的博客文章,从设置开始,展示了如何创建不是一个而是两个完全工作(虽然很简单)的工作流。

你可以在这里查看它,看看它是否有帮助。

第一个打印“Hello Activiti”的例子应该是你要找的。

于 2017-04-02T18:20:42.017 回答