jfinal集成activiti5.19

1、搭建好jfinal工程項目,或者直接從jfinal官網下載最新版本demomysql

2、導入activiti-5.19相關架包(spring相關架包除外)spring

3、將activiti引擎寫成jfinal插件的形式sql

  1. 建立插件類ActivitiPlugins實現IPlugin接口數據庫

  2. 實現相關方法ide

  代碼以下:ui


import org.activiti.engine.ProcessEngine;this

import org.activiti.engine.ProcessEngineConfiguration;url

import org.activiti.engine.ProcessEngines;spa


import com.jfinal.plugin.IPlugin;插件

import com.jfinal.plugin.activerecord.IDataSourceProvider;


public class ActivitiPlugins implements IPlugin {


@Override

public boolean start() {

// TODO Auto-generated method stub

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() {

// TODO Auto-generated method stub

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;

}


}

4、將編寫的插件放到jfinal插件集中運行

代碼以下:

/**

* 自定義插件

*/

@Override

protected void plugin(Plugins plugins) {

// 添加數據源

Prop p = PropKit.use("default/jdbc.config");

final String url = PropKit.get("activiti_url");

final String username = PropKit.get("activiti_user");

final String password = PropKit.get("activiti_pwd");

DruidPlugin druidPlugin = new DruidPlugin(url, username, password);

plugins.add(druidPlugin);

        //activiti 配置

        ActivitiPlugins activitiPlugins = new ActivitiPlugins(druidPlugin);   

        plugins.add(activitiPlugins);

}

5、到此便可運行項目

相關文章
相關標籤/搜索