package main;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task; public class MyBusinessProcessTest2 { public static void main(String[] args) {
// Create Activiti process engine
// ProcessEngines.init();
// System.out.println(ProcessEngines.getProcessEngines());
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
// Deploy the process definition
repositoryService.createDeployment()
.addClasspathResource("main/MyBusinessProcessTest.simpleProcessTest.bpmn20.xml")
.deploy();
// Get the first task
TaskService taskService = processEngine.getTaskService(); runtimeService.startProcessInstanceByKey("simpleProcess");
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
} /*public void simpleProcessTest() {
runtimeService.startProcessInstanceByKey("simpleProcess");
Task task = taskService.createTaskQuery().singleResult();
//assertEquals("Write monthly financial report", task.getName()); taskService.complete(task.getId());
//assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}*/
}

上面的代码会自动寻找activiti.cfg.xml文件。

<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"> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> <property name="jobExecutorActivate" value="false" /> <property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</bean> </beans>

也会自动寻找activiti-context.xml文件,内容如下:

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

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/activiti" />
<property name="username" value="root" />
<property name="password" value="" />
</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="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.H2Dictionary" />
</bean>
</property>
</bean> --> <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="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="managementService" factory-bean="processEngine" factory-method="getManagementService" /> </beans>

activiti-context.xml和activiti.cfg.xml这两个文件任意一个均可。

activiti_SpringEnvironment的更多相关文章

  1. activiti总结2

    根据流程号查询失败原因. activiti重试机制.齿轮节点.邮件节点.任务节点.ACT_HI_ACTINST历史表.ACT_RU_EXECUTION运行表.看图. 在Eclipse里面自己写个测试方 ...

随机推荐

  1. C++ STL基本容器的使用

    C++中有两种类型的容器:顺序容器和关联容器.顺序容器主要有vector.list.deque等.其中vector表示一段连续的内存,基于数组实现,list表示非连续的内存,基于链表实现,deque与 ...

  2. 使用飞信api接口实现短信发送(只能发送好友)

    找了很久才找到一个能用的飞信API接口(http://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号& ...

  3. noi 3531 判断整除

    3531:判断整除 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 一个给定的正整数序列,在每个数之前都插入+号或-号后计算它们的和.比如序列:1.2.4共有 ...

  4. UOJ 218 火车管理

    http://uoj.ac/problem/218 思路:建立一个可持久化线段树,代表这个位置的火车是哪辆,然后再弄一个线段树维护答案. 如果询问,直接询问线段树. 如果区间压入,直接在主席树上面压入 ...

  5. [Delphi]检查URL是否有效的函数

    function CheckUrl(url: string): boolean; var hSession, hfile, hRequest: hInternet; dwindex, dwcodele ...

  6. 14.1.3 检查InnoDB 可用性:

    14.1.3 Checking InnoDB Availability 14.1.3 检查InnoDB 可用性: 确定是否你的server 支持InnoDB: 1.执行命令 SHOW ENGINES; ...

  7. Wi-Fi定位,AP定位

    Wi-Fi实时定位系统 基于Wi-Fi的无线局域网实时定位系统(Wi-Fi RTLS)结合无线局域网络(WLAN).射频识别(RFID)和实时定位等多种技术,广泛地应用在有无线局域网覆盖的区域,实现复 ...

  8. COJN 0558 800600带通配符的字符串匹配

    800600带通配符的字符串匹配 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 通配符是一类键盘字符,当我们不知道真正字符或者 ...

  9. 跨站脚本(XSS)

    跨站脚本: cross-site scripting或者XSS, 即攻击者向目标Web站点注入HTML标签或者脚本 如果网站没有通过移除任何嵌入的HTML标签来消毒,那么web页面很容易受到跨站脚本攻 ...

  10. Delphi TdxBarmanager

    在 Form 上放一个 BarManager鼠标右键它,可以建立一个 MainToolBar,鼠标右键MainToolBar,建什么随便你选.只不过,最后设置一下 BarManager 的 Image ...