Hi
I am trying to run a spring boot instance with both a process defined in BPMN Modeller (xml) and another process with the help of Fluent API.
Has anyone an example for this? When I run it, i am only able to deploy one of the processes at one time.
Here is my spring boot setup, which seems to load the BPMN xml perfectly:
{code} @SpringBootApplication
public class CamundaApplication {
Logger logger = LoggerFactory.getLogger(CamundaApplication.class);
public static void main(String[] args) {
SpringApplication.run(CamundaApplication.class, args);
}
}{code}
When I add this, only one occurs in cockpit after restart:
{code}
@SpringBootApplication
@EnableProcessApplication
public class FluentAPI {
Logger logger = LoggerFactory.getLogger(FluentAPI.class);
@Autowired
private ProcessEngine processEngine;
@Bean
public BpmnModelInstance bpmnModelInstance() {
return Bpmn.createExecutableProcess("FluentAPI")
.name("Fluent API")
.executable()
.startEvent()
.id("StartEvent_1")
.serviceTask()
.name("Task1")
.camundaClass("javadelegate")
.camundaAsyncAfter()
.camundaAsyncBefore()
.serviceTask()
.name("Task2")
.camundaClass("WorkDelegate")
.endEvent()
.done();
}
public void deploy(){
processEngine.getRepositoryService()
.createDeployment()
.addModelInstance("model.bpmn", bpmnModelInstance())
.name("model")
.deploy();
}
@EventListener
public void onStart(PostDeployEvent event) {
logger.info("Waiting to start:)");
deploy();
}
}
{code}
You need to set springboot autoDepoymentResources=true, and make sure you put an entry for bpmn file in process.xml which should located in META-INF folder.
Seems like i have to add the @SpringBootApplication annotation for both the spring boot application class and the Fluent API class?
@SpringBootApplication
@EnableProcessApplication
public class FluentAPI {
@SpringBootApplication
public class CamundaApplication {
The annotations only belong on the CamundaApplication. Using the PostDeploy Eventlistener is the right idea, you could just put all code (model creation+deployment) in the handler method. And instead of using an autowired processEngine, use the one that come with the PostDeploy event.
The other answer with processes.xml and autodeployment is irrelevant for your use case since you are not trying to discover xml files in your jar, you are deploying by hand.
Just start simple (everything in the handler method), if you need an example, check this: https://github.com/holunda-io/holunda-spike/blob/master/cughh-camunda710/src/main/java/io/holunda/spike/cughh/c710/C710Application.java
@jangalinski So, you mean that the deploy of the FluentAPI process should lie in the class CamundaApplication? Like in your example code?
It can lie in any component known to spring (since you only rely on eventlistening), but until there is additional need to split, its good practice to keep application setup inside the application class.
So, if I use a own class for the fluent api process, i dont need to autowire anything without the @EventListener?
But in the Camundaapplication I need the following?
@SpringBootApplication
@EnableProcessApplication
your own class must be annotated with Component so your application componentScan finds it. Rest: yes!
Hi. First of all I want to thank you for helping me with this problem. I am very grateful.
I have added this class that defines the fluent api process below. But, it is ignored when I start up spring boot. I also have a BPMN file under resources for another process, that process is deployed as normal. I am not sure what I am doing wrong?
{package camunda.fluent;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class FluentAPI {
Logger logger = LoggerFactory.getLogger(FluentAPI.class);
public BpmnModelInstance bpmnModelInstance() {
return Bpmn.createExecutableProcess("FluentAPI")
.name("Fluent API")
.executable()
.startEvent()
.id("StartEvent_1")
.serviceTask()
.name("Create case")
.camundaClass("someDelegateClass")
.camundaAsyncAfter()
.camundaAsyncBefore()
.serviceTask()
.name("Start case work")
.camundaClass("SomeOtherDelegateClass")
.endEvent()
.done();
}
public void deploy(PostDeployEvent event){
event.getProcessEngine().getRepositoryService()
.createDeployment()
.addModelInstance("fluent-model.bpmn", bpmnModelInstance())
.name("fluent-model")
.deploy();
}
@EventListener
public void onStart(PostDeployEvent event) {
logger.info("Starting deploy of fluent API model :)");
deploy(event);
}
}}
This should work … would need more input … did you try my example
Here is my spring boot startup class:
@SpringBootApplication
public class MottakCamundaApplication {
Logger logger = LoggerFactory.getLogger(MottakCamundaApplication.class);
public static void main(String[] args) {
SpringApplication.run(MottakCamundaApplication.class, args);
}
}
Now only my bpmn file under resources are loaded into camunda.
@jangalinski The problem if I use your example, is that then the BPMN-file under resources are not loaded. Only the Fluent API process. Here is the code using your example:
package camunda;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.event.EventListener;
@SpringBootApplication
@EnableProcessApplication
public class CamundaApplication {
Logger logger = LoggerFactory.getLogger(CamundaApplication.class);
public static void main(String[] args) {
SpringApplication.run(CamundaApplication.class, args);
}
public BpmnModelInstance bpmnModelInstance() {
return Bpmn.createExecutableProcess("FluentAPI")
.name("Fluent API")
.executable()
.startEvent()
.id("StartEvent_1")
.serviceTask()
.name("Create case")
.camundaClass("JavaDelegate")
.camundaAsyncAfter()
.camundaAsyncBefore()
.serviceTask()
.name("Start case work")
.camundaClass("JavaDelegate")
.endEvent()
.done();
}
public void deploy(PostDeployEvent event){
event.getProcessEngine().getRepositoryService()
.createDeployment()
.addModelInstance("model.bpmn", bpmnModelInstance())
.name("model")
.deploy();
}
@EventListener
public void onStart(PostDeployEvent event) {
logger.info("Start load of Fluent API");
deploy(event);
}
}
do you have an (empty) META-INF/processes.xml? It’s required to trigger bpmn scan in combination with the EnableprocessApplication annotation.