This example demonstrates how you can build a Spring Boot application having following configured:
- Embedded Camunda engine
- Process application and BPMN process automatically deployed on engine startup
- Usage of
@PostDeploy
startup hook - occurs after the process application is deployed
- To embed Camunda Engine you must add following dependency to your
pom.xml
:
...
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter</artifactId>
<version>7.16.0</version>
</dependency>
...
- With Spring Boot you usually create an "application" class annotated with
@SpringBootApplication
. In order to have a Camunda process application registered, you can simply add the annotation@EnableProcessApplication
to the same class and also include theprocesses.xml
file to yourMETA-INF
folder:
@SpringBootApplication
@EnableProcessApplication
public class AutoDeploymentApplication {
public static void main(final String... args) throws Exception {
SpringApplication.run(AutoDeploymentApplication.class, args);
}
}
-
You can also put BPMN, CMMN and DMN files in your classpath, they will be automatically deployed and registered within the process application.
-
When implementing the process application in standard manner, you can use method-level annotations
@PostDeploy
and@PreUndeploy
to process corresponding events. In case of a Spring Boot process application you can handle this events by using Spring @EventListener annotation with following event classes:PostDeployEvent
andPreUndeployEvent
.
...
@EventListener
public void notify(final PostDeployEvent event) {
...
}
...
You can then build the application with mvn clean install
and then run it with java -jar
command.
Observe the log entry similar to this:
Found deployed process: ProcessDefinitionEntity[Sample:1:215245a1-a1e2-11e7-8069-0a0027000006]