公司现有的工作流是比较老的JBPM,用起来不太方便,经常性的流程跑一半就停止不前了。闲暇之余学习下activiti的使用,基本配置如下:

1、创建pom.xml文件所依赖的jar包

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ccb</groupId>
<artifactId>activiti</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>activiti Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.14.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.14.RELEASE</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<!-- <scope>test</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-bpmn-converter -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-converter</artifactId>
<version>6.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-bpmn-model -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>6.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-image-generator -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-image-generator</artifactId>
<version>6.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-process-validation -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-process-validation</artifactId>
<version>6.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- <dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-root</artifactId>
<version>6.0.0</version>
</dependency> --> <!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>6.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>6.0.0</version>
</dependency> </dependencies>
<build>
<finalName>activiti</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<!-- maven加载src下的xml文件 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
</project>

pom.xml

注意加载日志包时log4j和slf4j的版本匹配,启动服务时需要依赖log4j.properties配置文件。

这里使用的mybatis框架,数据库使用的mysql。

2、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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--配置数据源-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!--配置数据库中的中文乱码-->
<property name="url" value="jdbc:mysql://localhost:3306/activiti? useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123456lq"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
<property name="defaultAutoCommit" value="false"></property>
</bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"></property>
<property name="databaseSchemaUpdate" value="true"/>
</bean>
<!-- <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="databaseSchemaUpdate" value="true"/>
</bean> -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>

activiti.cfg.xml

这里使用的是dbcp连接池,也可以自行配置其他的。

3、初始化数据库表执行类

 package com.ccb.commons;

 import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test; /**
* 初始化MYSQL数据库中activiti工作流需要用到的表28个
* @author 刘强
*
*/
public class CreateInitTableUtils {
//private static final Logger log =LoggerFactory.getLogger(CreateInitTableUtils.class);
@Test
public void createTable(){
ProcessEngineConfiguration configuration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = configuration.buildProcessEngine();
//log.info(processEngine.toString());
System.out.println(processEngine);
}
}

CreateInitTableUtils.java

4、spring-servlet.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 注解方法,暂未开启 -->
<!-- <mvc:annotation-driven/>
<mvc:default-servlet-handler/> -->
<!-- 解决返回jsp页面省略后缀写法 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 支持文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="5000000"/> </bean> <!-- 需要扫描的包 -->
<context:component-scan base-package="com.ccb.*.dao"></context:component-scan> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!--配置数据库中的中文乱码-->
<property name="url" value="jdbc:mysql://localhost:3306/activiti? useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123456lq"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
<property name="defaultAutoCommit" value="false"></property>
</bean>
<!-- 加载配置的 *.mbm.xml文件-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="mapperLocations">
<list>
<value>classpath:com.ccb.activiti.dto/*.mbm.xml</value>
</list>
</property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<!-- <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0">
<ref bean="sqlSessionFactory" />
</constructor-arg>
</bean> --> <!-- 动态代理实现 不用写dao的实现 -->
<bean id="MapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 这里的basePackage 指定了dao层接口路劲,这里的dao接口不用自己实现 -->
<property name="basePackage" value="com.ccb.activiti.dao" />
<!-- 如果只有一个数据源的话可以不用指定,但是如果有多个数据源的话必须要指定 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<!-- 直接制定了sqlsessionTemplate名称,这个和上面的其实是一样的 -->
<property name="sqlSessionTemplateBeanName" value="sqlSession" />
</bean>
<!-- 事物管理 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="datasource"></property>
</bean>
</beans>

spring-servlet.xml

5、具体业务逻辑封装管理类

 package com.ccb.commons;

 import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipInputStream; import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* 具体业务逻辑封装管理类
* @author 刘强
*
*/
public class ProjectInitManager { private ApplicationContext applicationContext; private ProcessEngineConfiguration configuration; public ProjectInitManager() {
applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring-mabatis.xml"});
configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
}
public Object getBeanByName(String name){
return applicationContext.getBean(name);
} public ProcessEngine getProcessEngine(){
return configuration.buildProcessEngine();
} //发布流程
public void deployProcess(String ProcessFileName){
InputStream inputStream =
this.getClass().getClassLoader().getResourceAsStream(ProcessFileName);
getProcessEngine().getRepositoryService().createDeployment()
.addInputStream(ProcessFileName, inputStream).deploy();
} //批量发布流程
public void deployProcessByZip(String processFileName) throws IOException{
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(processFileName));
Deployment deployment =
getProcessEngine().getRepositoryService().createDeployment()
.addZipInputStream(zipInputStream).deploy(); } public RepositoryService getRepositoryService(){
return getProcessEngine().getRepositoryService();
} public FormService getFormService(){
return getProcessEngine().getFormService();
} public HistoryService getHistoryService(){
return getProcessEngine().getHistoryService();
} public IdentityService getIdentityService(){
return getProcessEngine().getIdentityService();
} public ManagementService getManagementService(){
return getProcessEngine().getManagementService();
} public RuntimeService getRuntimeService(){
return getProcessEngine().getRuntimeService();
} public TaskService getTaskService(){
return getProcessEngine().getTaskService();
}
//初始化数据库
public void initActivitiData(){
getProcessEngine();
}
}

ProjectInitManager.java

其他的具体实现类,controller,service,dao层逻辑就不一一列举了。

activiti初学的更多相关文章

  1. Activiti初学问题,求解

    <userTask id="writeReportTask" name="Write monthly financial report" > < ...

  2. activiti数据库表结构全貌解析

    http://www.jianshu.com/p/e6971e8a8dad 下面本人介绍一些activiti这款开源流程设计引擎的数据库表结构,首先阐述:我们刚开始接触或者使用一个新的东西(技术)时我 ...

  3. Activiti初学者教程

    http://wenku.baidu.com/view/bb7364ad4693daef5ff73d32.html 1. 初识Activiti 1.1. 工作流与工作流引擎 工作流(workflow) ...

  4. Activiti初学者教程 (zhuan)

    http://blog.csdn.NET/bluejoe2000/article/details/39521405 ****************************************** ...

  5. 工作流Activiti新手入门学习路线整理

    写在前面: 最近项目中使用到了工作流,虽然此部分不是自己需要完成的,但是也涉及到了要调用写的接口.正好有时间,就了解下,以便之后能在其他项目中用到时,不至于什么都不知道什么都不了解. 这里就主要整理下 ...

  6. DDD初学指南

    去年就打算总结一下,结果新换的工作特别忙,就迟迟没有认真动手.主要内容是很多初学DDD甚至于学习很长时间的同学没有弄明白DDD是什么,适合什么情况.这世界上没有银弹,抛开了适合的场景孤立的去研究DDD ...

  7. 流程开发Activiti 与SpringMVC整合实例

    流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...

  8. gulp初学

    原文地址:gulp初学 至于gulp与grunt的区别,用过的人都略知一二,总的来说就是2点: 1.gulp的gulpfile.js  配置简单而且更容易阅读和维护.之所以如此,是因为它们的工作方式不 ...

  9. 初学seaJs模块化开发,利用grunt打包,减少http请求

    原文地址:初学seaJs模块化开发,利用grunt打包,减少http请求 未压缩合并的演示地址:demo2 学习seaJs的模块化开发,适合对seajs基础有所了解的同学看,目录结构 js — —di ...

随机推荐

  1. map文件的使用

    map文件相信大家并不陌生,大家都知道是用来调试的,但是具体怎么用你又清不清楚呢? 其实也很简单 1.拿JQ为例,我们需要备有jquery.js.jquery.min.js.jquery.min.ma ...

  2. python---django中form组件(2)自定制属性以及表单的各种验证,以及数据源的实时更新,以及和数据库关联使用ModelForm和元类

    自定义属性以及各种验证 分析widget: class TestForm(forms.Form): user = fields.CharField( required = True, widget = ...

  3. Matrix67|自由职业者,数学爱好者

    Matrix67|自由职业者,数学爱好者 介绍一下你自己和所做的工作. 我叫顾森,网名 Matrix67,长住北京的重庆人,目前没有固定的职业.一会儿当当码农,一会儿做做编辑,一会儿教教数学,一会儿写 ...

  4. 小记 HTML5 file对象

    <input type="file" id="myfile" multiple> 这是个很普通的 file 上传组件,multiple 是支持多选, ...

  5. <header><footer>引用

    示例:http://www.w3school.com.cn/html/html_layout.asp

  6. PHP扩展开发--编写一个helloWorld扩展

    为什么要用C扩展 C是静态编译的,执行效率比PHP代码高很多.同样的运算代码,使用C来开发,性能会比PHP要提升数百倍. 另外C扩展是在进程启动时加载的,PHP代码只能操作Request生命周期的数据 ...

  7. Strange Queries(莫队)

    题目 You are given an array with n integers a1, a2, ..., an, and q queries to answer. Each query consi ...

  8. 【配置】Spring和MyBatis整合

    spring配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...

  9. Caffe 碎碎念

    Window Data Layer window data layer 的数据是存在硬盘上的图片, 需要在一个txt里指定用于训练或测试的图片以及bounding box, bounding box ...

  10. H - Tickets dp

    题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...