This example only uses camunda-bpm-spring-boot-starter, so it does not start an embedded tomcat and provides no REST API.
It demonstrates how Camunda can be used in combination with Spring Boot to spawn a node that:
- connects to a database (and sets it up if needed, in this case h2 in memory db)
- configures and starts a process engine
- deploys the 'sample.bpmn' process
- starts this process
- automatically executes the user task
- JobExecutor executes async service task
- once the process instance is ended, the spring boot application terminates
It also demonstrates the usage of application.yaml configuration file and contains a couple of integration tests, showing how this can be tested.
- Java 17/21
- To embed Camunda Engine you must add the following dependency to your
pom.xml:
...
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter</artifactId>
<version>7.24.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@EnableProcessApplicationto the same class and also include theprocesses.xmlfile in yourMETA-INFfolder:
@SpringBootApplication
@EnableProcessApplication("mySimpleApplication")
public class SimpleApplication {
public static void main(final String... args) throws Exception {
SpringApplication.run(SimpleApplication.class, args);
}
}-
You can simply inject the engine services in your Spring beans using the
@Autowiredannotation. -
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
@PostDeployand@PreUndeployto 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:PostDeployEventandPreUndeployEvent.
...
@EventListener
public void notify(PostDeployEvent event) {
...
}
...You can build the application with mvn clean install and then run it with the java -jar command.
Observe the log entries similar to these:
postDeploy: PostDeployEvent{processEngine=org.camunda.bpm.engine.impl.ProcessEngineImpl@6973b51b}
started instance: 0f1cd511-a1f0-11e7-8e5d-0a0027000006
completed task: Task[0f200964-a1f0-11e7-8e5d-0a0027000006]
executed sayHelloDelegate: ProcessInstance[380e1597-a206-11e7-8d39-0a0027000006]
processinstance ended!
preUndeploy: PreUndeployEvent{processEngine=org.camunda.bpm.engine.impl.ProcessEngineImpl@3be4ea5e}