Configuring Activiti Database

In this example we will learn how to configure Activiti to use another Relational Database. We will switch from the default H2 database to PostgreSQL.

You can configure a different database using two main strategies:

Programmatic configuration

Using a Programmatic configuration, you will define the ProcessEngineConfiguration and set JDBC parameters as follows:

ProcessEngineConfiguration config = (StandaloneProcessEngineConfiguration)ProcessEngineConfiguration
        ProcessEngine processEngine = config.buildProcessEngine();

Declarative configuration in activiti.cxf.xml

On the other hand, you can use the main Activiti configuration file and define the JDBC settings in the StandaloneProcessEngineConfiguration Bean as in the following example:

<beans xmlns=""

	<bean id="processEngineConfiguration"

		<property name="databaseType" value="postgres" />
		<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/activiti" />
		<property name="jdbcDriver" value="org.postgresql.Driver" />
		<property name="jdbcUsername" value="postgres" />
		<property name="jdbcPassword" value="postgres" />

		<!-- <property name="dataSource" ref="dataSource" /> -->

		<!-- Database configurations -->
		<property name="databaseSchemaUpdate" value="create-drop" />

		<!-- job executor configurations -->
		<property name="jobExecutorActivate" value="true" />

		<property name="createDiagramOnDeploy" value="false" />



In terms of code, you will need to configure the RespositoryService to use the configuration provided by Activiti configuration as follows:

final RepositoryService repositoryService = processEngine.getRepositoryService();

Here is where you can place the activiti.cfg.xml in the DemoActiviti project that we have uploaded on github at:

├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── mastertheboss
    │   │           ├── activiti
    │   │           │   └── DemoActiviti
    │   │           │       └──
    │   │           └── task
    │   │               └──
    │   └── resources
    │       ├── activiti.cfg.xml
    │       └── DemoProcess.bpmn

Adding the JDBC Driver in the pom.xml

Finally, whahever is your approach to configuring JDBC, you have to include the driver libraries in your application. If you are using Maven, then include the database JDBC driver in the pom.xml