1.下载activiti-5.3 www.activiti.org
2.C:\activiti-5.3\activiti-5.3\setup
修改build.properties db=mysql
修改build.mysql
db=mysql
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/activiti?autoReconnect=true
jdbc.username=activiti
jdbc.password=activiti
运行ant db.create
2.新建项目,把C:\activiti-5.3\activiti-5.3\workspace\activiti-spring-examples拷贝到项目中
如果运行了ant demo.setup 在这个目录下会有libs-runtime libs-test 把相关类库添加到项目中
3.修改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?autoReconnect=true" />
<property name="username" value="activiti" />
<property name="password" value="activiti" />
</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="persistenceXmlLocation">
<value>classpath:custom-persistence.xml</value>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
</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" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"></bean>
</beans>
4.新建一个过程定义文件financialReport.bpmn20.xml(从10分钟教程中copy过来的)
5.新建一个测试用例,测试发布,任务获取整个过程
package com.brsy.test;import java.util.List;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.identity.GroupEntity;
import org.activiti.engine.impl.identity.UserEntity;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration("classpath:activiti-context.xml")
public class TestAll extends SpringActivitiTestCase {
protected IdentityService identityService;
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
@Test
public void testAll(){
identityService = applicationContext.getBean(IdentityService.class);
UserEntity user = new UserEntity();
user.setId("webcat");
user.setFirstName("wang");
user.setLastName("peiling");
user.setPassword("password");
identityService.saveUser(user);
GroupEntity group = new GroupEntity();
group.setId("test");
group.setName("test");
group.setType("1");
identityService.saveGroup(group);
identityService.createMembership("webcat", "test");
repositoryService = applicationContext.getBean(RepositoryService.class);
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("com/brsy/test/financialReport.bpmn20.xml")
.deploy();
runtimeService = applicationContext.getBean(RuntimeService.class);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("financialReport");
List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("webcat").list();
System.out.println("tasks=========" + tasks.size());
}
}
参考http://rongjih.blog.163.com/blog/static/33574461201011345145978/