一、使用配置类
@Test public void testGetProcessEngine1() { //获取ProcessEngineConfiguration对象 ProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration(); //配置相关数据库的连接信息 configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver"); configuration.setJdbcUsername("root"); configuration.setJdbcPassword("123456"); configuration.setJdbcUrl("jdbc:mysql://localhost:3306/flowable?serverTimezone=UTC"); configuration.setActivityFontName("宋体"); configuration.setLabelFontName("宋体"); configuration.setAnnotationFontName("宋体"); //如果书库中的表结构不存在就新建 configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); ProcessEngine processEngine = configuration.buildProcessEngine(); }
二、使用默认XML
flowable.cfg.xml
<beans xmlns="http://www.springframework.org/schema/beans" 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"> <bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/flowable?serverTimezone=UTC" /> <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver" /> <property name="jdbcUsername" value="root" /> <property name="jdbcPassword" value="123456" /> <property name="databaseSchemaUpdate" value="true" /> <property name="asyncExecutorActivate" value="false" /> </bean> </beans>
/** * 流程部署 */ @Test public void testGetProcessEngine2() { ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine(); System.out.println("defaultProcessEngine = " + defaultProcessEngine); }
三、使用自定义XML
@Test public void testGetProcessEngine3() { ProcessEngineConfiguration configuration = ProcessEngineConfiguration .createProcessEngineConfigurationFromResource("flowable.cfg.xml"); ProcessEngine processEngine = configuration.buildProcessEngine(); System.out.println("processEngine = " + processEngine); }