1.通过ProcessEngineConfiguration获取
package cn.lonecloud.mavenActivi;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;
/**
* 通过使用ProcessEngineConfiguration获取
*/
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文件:
<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="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!-- 配置流程引擎配置对象 -->
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf-8"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="123456"></property>
<!-- 注入数据源信息 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<!-- 注入自动建表设置 -->
<property name="processEngineConfiguration" ref="processEngineConfiguration"></property>
</bean>
</beans>
java
package cn.lonecloud.mavenActivi;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.junit.Test;
/**
* 通过通过配置文件进行初始化获取引擎对
*/
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进行获取
@Test
public void configByDefault(){
//通过获取载入默认获取
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
processEngine.close();
}
这里的xml文件名必须设置为activiti.cfg.xml