I have a Controller:
@RestController
@RequestMapping("processes")
public class ProcessController {
@Autowired
private ProcessEngine processEngine;
@Autowired
private RepositoryService repositoryService;
@GetMapping
public List<ProcessDefinition> listProcess() {
return processEngine.getRepositoryService().createProcessDefinitionQuery().list();
}
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Deployment addProcess(@RequestPart MultipartFile file) throws IOException {
return repositoryService.createDeployment().addInputStream(file.getOriginalFilename(), file.getInputStream()).deploy();
}
}
And I have already upload the test.bpmn20.xml
with the addProcess()
method, but when I want to get ProcessDefinition list with the listProcess
method, the console warning:
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot invoke "org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.getIdentityLinkServiceConfiguration()" because "processEngineConfiguration" is null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Cannot invoke "org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.getIdentityLinkServiceConfiguration()" because "processEngineConfiguration" is null (through reference chain: java.util.ArrayList[0]->org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl["identityLinks"])]
My POM.xml:
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.7.2</version>
</dependency>
Why console warning this? What can I do?
Pls help me, thx!
To return a variable from a REST endpoint in Spring it needs to convert the variable to a JSON. However, Flowable API responses are not optimized to be converted to DTOs. That is why you may not be able to return them directly as a response variable.
For example:
@RestController
@RequestMapping("processes")
public class ProcessController {
@Autowired
private ProcessEngine processEngine;
@Autowired
private RepositoryService repositoryService;
// ...
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public DeploymentDto addProcess(@RequestPart MultipartFile file) throws IOException {
Deployment deployment = repositoryService.createDeployment()
.addInputStream(file.getOriginalFilename(), file.getInputStream())
.deploy();
return new DeploymentDto(deployment);
}
private static class DeploymentDto {
private final String id;
private final String name;
public DeploymentDto(Deployment deployment) {
this.id = deployment.getId();
this.name = deployment.getName();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}
}
You can create your own DTO objects and map the result from the Flowable API to your DTO. Alternatively, you could use the flowable-spring-boot-starter-rest
dependency which gives you out-of-the-box REST endpoints. The mapping there is automatically handled for you. (See the getting started guide for more information https://www.flowable.com/open-source/docs/bpmn/ch05a-Spring-Boot/#getting-started)