jfinal4.9整合activiti7.1

本文参考的链接:https://blog.csdn.net/weixin_28836507/article/details/114159231?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&spm=1001.2101.3001.4242

jfinal版本4.9.08,activiti7.1

1、在创建好的jfinalmaven版本下,pom.xml添加:

 <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-engine</artifactId>

            <version>7.1.0.M6</version>

        </dependency>

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-bpmn-model</artifactId>

            <version>7.1.0.M6</version>

        </dependency>

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-bpmn-converter</artifactId>

            <version>7.1.0.M6</version>

        </dependency>

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-json-converter</artifactId>

            <version>7.1.0.M6</version>

        </dependency>

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-bpmn-layout</artifactId>

            <version>7.1.0.M6</version>

        </dependency>

2、创建插件类ActivitiPlugins

import org.activiti.engine.ProcessEngine;

import org.activiti.engine.ProcessEngineConfiguration;

import org.activiti.engine.ProcessEngines;

import com.jfinal.plugin.IPlugin;

import com.jfinal.plugin.activerecord.IDataSourceProvider;


public class ActivitiPlugins implements IPlugin {

@Override

public boolean start() {

if (isStarted) {

return true;

}


processEngineConfiguration = ProcessEngineConfiguration

.createStandaloneProcessEngineConfiguration()

.setDatabaseType("mysql")

.setDataSource(this.dataSourceProvider.getDataSource())

.setTransactionsExternallyManaged(true) // 使用托管事务工厂

.setDatabaseSchemaUpdate(


ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);// 数据库中没有表则创建表

// .buildProcessEngine();//开启流程引擎

// processEngine.getRepositoryService();

// configuration

System.out.println("流程引擎111:" + buildProcessEngine());

// System.out.println("流程部署服务:"+processEngine.getRepositoryService());

isStarted = true;

// ProcessEngines.init();//开启流程引擎

System.out.println("启动流程引擎.......");

return isStarted;


}


@Override

public boolean stop() {

ProcessEngines.destroy();// 关闭流程引擎

isStarted = false;

return true;

}


// 开启流程服务引擎

public static ProcessEngine buildProcessEngine() {

if (processEngine == null)

if (processEngineConfiguration != null) {

processEngine = processEngineConfiguration.buildProcessEngine();

}

return processEngine;

}


private static ProcessEngine processEngine = null;

private static ProcessEngineConfiguration processEngineConfiguration = null;


// 基本属性 url、user、password

private IDataSourceProvider dataSourceProvider = null;

private boolean isStarted = false;


public ActivitiPlugins(IDataSourceProvider dataSourceProvider) {

this.dataSourceProvider = dataSourceProvider;

}


// get/set方法

public IDataSourceProvider getDataSourceProvider() {

return dataSourceProvider;

}


public void setDataSourceProvider(IDataSourceProvider dataSourceProvider) {

this.dataSourceProvider = dataSourceProvider;

}

}

3、在启动类中,configPlugin(Plugins me)方法注册ActivitiPlugins插件

//activiti 插件配置

DruidPlugin druidPlugin2 = new DruidPlugin(p.get("jdbcUrl2"), p.get("user"), p.get("password").trim());

me.add(druidPlugin2);

ActivitiPlugins activitiPlugins = new ActivitiPlugins(druidPlugin2);

me.add(activitiPlugins);

4、自己创建对应数据库,并且在jfinal配置文件修改对应数据库连接信息,以下是我自己配置:

jfinal启动类默认配置:我的配置文件是config.txt,在src/main/resources下面

static void loadConfig() {

if (p == null) {

p = PropKit.useFirstFound("demo-config-pro.txt", "config.txt");

}

}

config.txt:

# config

jdbcUrl = jdbc:mysql://localhost/数据库名?characterEncoding=utf8&useSSL=false&serverTimezone=GMT

user = root

password =123456

jdbcUrl2 = jdbc:mysql://localhost/数据库名?characterEncoding=utf8&useSSL=false&serverTimezone=GMT


说明:jdbcUrl2是创建一个新的数据库,专门存放activiti自动生成的表,jdbcUrl是自己另外一个业务系统数据库,两者分开,方便查看调试。

5、最后运行启动类,可以发现对应数据库自动生成25张表,到此就可以快乐玩转activiti7

360截图20210511212850947.jpg

评论区

yuwen01

2021-05-11 21:35

补充一下,我连接的是mysql数据库,版本是8以上,需要导入对应jar包,

mysql
mysql-connector-java
8.0.17

zzutligang

2021-05-12 14:01

好东西,赞一个!

zeroabc

2021-05-12 15:45

工作流!

steven_lhcb_9527

2021-05-17 11:11

非常棒

李通

2021-05-18 18:32

@yuwen01 如果再有一个activiti的案例,验证activiti功能就更好了

yuwen01

2021-05-19 08:54

@李通 来了 https://jfinal.com/share/2414