So far, we have created a process using the Designer and Modeler and deployed it using the Activiti Explorer. We have seen that configuration can be done using activiti-standalone-context.xml
. Similar configurations can also be done using the ProcessEngine
class. In this section, we will take a look at this and in Chapter 6, The Activiti ProcessEngine API, we will see more details regarding various APIs.
We can create the Activiti Process Engine using the org.activiti.engine.ProcessEngines
class. To configure the Process Engine, we have to create the activiti.cfg.xml
file.
Let's see how we can run the Activiti Engine.
Firstly, we can create an instance of ProcessEngine
as follows:
ProcessEngineprocessEngine = ProcessEngines.getDefaultProcessEngine()
This instance will search for the activiti.cfg.xml
file and create a Process Engine based on the configuration defined in that file.
We can configure the file using the following configuration properties:
<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="mailServerHost" value="mail.demo.com" /> <property name="mailServerPort" value="25" /> </bean> </beans>
This configuration is done for the Spring environment.
It is not mandatory to create the configuration of ProcessEngine
in the Spring environment. We can also create an object of ProcessEngineConfiguration
programmatically in the configuration file. We can also use a different bean ID.
Using the following code, we can create ProcessEngine
:
ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault(); ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource); ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName); ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream); ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);
All the
ProcessEngineConfiguration.createXXX()
methods return a ProcessEngineConfiguration
instance that can be used further.
ProcessEngine
is created after calling the buildProcessEngine()
method as follows:
ProcessEngineprocessEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration() .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000") .setJobExecutorActivate(true) .buildProcessEngine();
We learned about the class that is used to create the Process Engine. Now we know which properties are required in the activiti.cfg.xml
file for the Process Engine. We learned to create the Activiti Process Engine without using the Spring environment.
Now that you've gone through the chapter, feel free to attempt the following activities:
Q1. Which bean ID is used for configuring the mail server's properties?
transactionManager
datasource
ProcessEngineConfiguration
processEngine
Q2. Which file is used to configure the production database in the Spring environment?
db.properties
activiti-standalone-context.xml
web.xml
rebel.xm
Q3. Which layer is optional in Activiti?