1.通过ProcessEngineConfiguration获取
package cn.lonecloud.mavenActivi;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
/**
* 通过使用ProcessEngineConfiguration获取
* @Title: ConfigByClass.java
* @Package cn.lonecloud.mavenActivi
* @Description:
* @author lonecloud
* @date 2016年8月22日 下午10:50:33
*/
public class ConfigByClass {
@Test
public void config() {
//获取config对象
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
//Jdbc设置
String jdbcDriver = "com.mysql.jdbc.Driver";
processEngineConfiguration.setJdbcDriver(jdbcDriver);
String jdbcUrl = "jdbc:mysql://localhost:3306/mavenActiviti?useUnicode=true&characterEncoding=utf-8";
processEngineConfiguration.setJdbcUrl(jdbcUrl);
String jdbcUsername = "root";
processEngineConfiguration.setJdbcUsername(jdbcUsername);
String jdbcPassword = "123456";
processEngineConfiguration.setJdbcPassword(jdbcPassword);
/**
* Checks the version of the DB schema against the library when the
* process engine is being created and throws an exception if the
* versions don't match.
*/
// public static final String DB_SCHEMA_UPDATE_FALSE = "false";//不自动创建新表
/**
* Creates the schema when the process engine is being created and drops
* the schema when the process engine is being closed.
*/
// public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";//每次运行创建新表
/**
* Upon building of the process engine, a check is performed and an
* update of the schema is performed if it is necessary.
*/
// public static final String DB_SCHEMA_UPDATE_TRUE = "true";设置自动对表结构进行改进和升级
//设置是否自动更新
processEngineConfiguration
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//获取引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
processEngine.close();
}
}
2.通过ProcessEngineConfiguration载入xml文件
xml文件:
java代码
package cn.lonecloud.mavenActivi;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.junit.Test;
/**
* 通过通过配置文件进行初始化获取引擎对
* @Title: ConfigByConfig.java
* @Package cn.lonecloud.mavenActivi
* @Description:
* @author lonecloud
* @date 2016年8月22日 下午10:40:35
*/
public class ConfigByConfig {
/**
* 通过配置文件进行初始化获取引擎对象
* @Description:
*/
@Test
public void configByConf(){
//载入资源
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//创建引擎
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
processEngine.getRepositoryService();
}
}
3.通过默认载入activiti.cfg.xml进行获取
* 通过默认载入activiti.cfg.xml进行获取
* @Description:推荐使用
*/
@Test
public void configByDefault(){
//通过获取载入默认获取
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
processEngine.close();
}
这里的xml文件名必须设置为activiti.cfg.xml