美文网首页
3.1 创建ProcessEngine

3.1 创建ProcessEngine

作者: 精简明了 | 来源:发表于2019-01-26 08:58 被阅读0次

通过名为的XML文件配置activiti.cfg.xml(使用Spring样式构建流程引擎,则不适用)

获得a的最简单方法ProcessEngine是使用org.activiti.engine.ProcessEngines类

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()

这将activiti.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.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">

    <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />

    <property name="databaseSchemaUpdate" value="true" />

    <property name="jobExecutorActivate" value="false" />
    <property name="asyncExecutorEnabled" value="true" />
    <property name="asyncExecutorActivate" value="false" />

    <property name="mailServerHost" value="mail.my-corp.com" />
    <property name="mailServerPort" value="5025" />
  </bean>

</beans>

配置XML实际上是一个Spring配置。这并不意味着Activiti只能在Spring环境中使用!我们只是在内部利用Spring的解析和依赖注入功能来构建引擎
ProcessEngineConfiguration对象也可以使用配置文件以编程方式创建。也可以使用不同的bean id

ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);

也可以不使用配置文件,并根据默认值创建配置(有关更多信息,请参阅不同的受支持类

ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();

如果需要,所有这些ProcessEngineConfiguration.createXXX()方法都返回ProcessEngineConfiguration可以进一步调整的方法。调用buildProcessEngine()操作后,ProcessEngine创建一个:

ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
  .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
  .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
  .setAsyncExecutorEnabled(true)
  .setAsyncExecutorActivate(false)
  .buildProcessEngine();

相关文章

网友评论

      本文标题:3.1 创建ProcessEngine

      本文链接:https://www.haomeiwen.com/subject/mlwbjqtx.html