Activiti初始化数据库三种方式

Activiti环境搭建
目标: 通过配置,创建ProcessEngine核心对象,来检测Activiti环境是否搭建成功!!
成功的标准: 能够获取ProcessEngine的实例;数据库需要自动创建表
1、硬编码方式

// 1、创建ProcessEngine配置对象 
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
// 2、做配置
configuration.setJdbcUrl("jdbc:mysql://localhost:3306/activiti?createDatabaseIfNotExist=true");
configuration.setJdbcDriver("com.mysql.jdbc.Driver");
configuration.setJdbcUsername("root");
configuration.setJdbcPassword("admin");

// 配置建表策略       
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

// 3、创建ProcessEngine 
ProcessEngine processEngine = configuration.buildProcessEngine(); 

System.out.println("processEngine" + processEngine);

2、配置方式
java文件

// 1、创建配置对象(加载配置文件)
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// 2、通过配置对象,创建ProcessEngine
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println("processEngine" + processEngine);

XML文件

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?createDatabaseIfNotExist=true" />
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUsername" value="root" />
    <property name="jdbcPassword" value="admin" />
    
    <property name="databaseSchemaUpdate" value="true" />
    
bean>

3、项目方式

// 1、创建ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println("processEngine" + processEngine);

你可能感兴趣的:(Activiti)