我正在尝试使用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
答案 0 :(得分:1)
这里的内容看起来不错。您是否查看过activiti explorer以确保您的流程正确部署?您也可以在资源管理器中练习您的过程。在您开始在代码中使用它之前,这可用作完整性检查。
该流程名称看起来有点滑稽。通常,当您通过资源管理器将进程部署到activiti时,它会将一个版本号附加到进程名称,如“myProcess:23”。此扩展名称是您用于实例化该过程的名称。
答案 1 :(得分:1)
这段代码完全错误。要测试您的过程,请查看文档的this章节,或者仅使用Activiti Explorer作为Hethcox建议。如果您想更正现有的应用程序,请阅读process engine in a web application章节
答案 2 :(得分:1)
我已经写了一篇关于此的超级详细博客文章,从设置开始,展示了如何创建一个而不是两个完全有效(尽管简单)的工作流程。
您可以查看here并查看是否有帮助。
第一个打印&#34; Hello Activiti&#34;应该是你想要的。