概述:ProcessEngineConfiguration对象代表一个Activiti流程引擎的全部配置,该类提供一系列创建ProcessEngineConfiguration实例的静态方法,这些方法用于读取和解析相应的配置文件,并返回ProcessEngineConfiguration的实例。出这些静态方法外,该类为其他可配置的引擎属性提供相应的setter和getter方法
此处用到的所有类关系如下图:
说明:
<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-->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--"&"是转义符,代表"&"-->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/act?useSSL=false&characterEncoding=UTF-8" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="123456" />
<!--该属性有三个取值,说明如下:
1. false: false为默认值,设置为该值后, Activiti 在启动时, 会对比数据库表中保存的版本,
如果没有表或者版本不匹配时, 将在启动时抛出异常。
2. true: 设置为该值后, Activiti 会对数据库中所有的表进行更新, 如果表不存在, 则Activiti 会自动创建。
3. create-drop: Activiti 启动时, 会执行数据库表的创建操作, 在 Activiti 关闭时, 执行数据库表的删除操作。
-->
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
ProcessEngineConfiguration configuration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
System.out.println(configuration.getJdbcUrl());
//结果:jdbc:mysql://localhost:3306/act
//1.指定配置文件创建ProcessEngineConfiguration:
//Activiti会到ClassPath下查找my-activiti1.xml的配置文件,并创建名称为"processEngineConfiguration的bean
ProcessEngineConfiguration configuration1 =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my-activiti1.xml");
System.out.println(configuration1.getJdbcUrl());
//结果:jdbc:mysql://localhost:3306/act
//2.指定配置文件创建ProcessEngineConfiguration,两个参数:第一个为配置文件位置,第二个为创建bean的名称
ProcessEngineConfiguration configuration2 =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my-activiti2.xml","test");
System.out.println(configuration2.getJdbcUrl());
//结果:jdbc:mysql://localhost:3306/act
说明:
//读取输入流的配置,file的根目录是项目名称的位置:此处即为first-activiti
File file = new File("test/input-stream.xml");
InputStream inputStream = new FileInputStream(file);
ProcessEngineConfiguration configuration3 = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream);
System.out.println(configuration3.getJdbcUrl());
//结果:jdbc:mysql://localhost:3306/act
ProcessEngineConfiguration configuration4 = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
System.out.println(configuration4.getJdbcUrl());
System.out.println(configuration4.getDatabaseSchemaUpdate());
//结果:
//jdbc:h2:mem:activiti
//create-drop
ProcessEngineConfiguration configuration5 = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
System.out.println(configuration5.getJdbcUrl());
System.out.println(configuration5.getDatabaseSchemaUpdate());
//结果:
//jdbc:h2:tcp://localhost/~/activiti
//false
看《疯狂workflow讲义第二版》