activiti 7.1.0.M6 整合 springboot 2.7.4 无法获取repositoryService
时间: 2023-02-16 17:30:30 浏览: 136
Activiti 7.1.0.M6 与 Spring Boot 2.7.4 整合时,如果无法获取 repositoryService,可能是因为 Activiti 的配置类中没有配置 repositoryService 的 Bean。请确保 Activiti 的配置类中有以下代码:
```
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
return processEngine.getRepositoryService();
}
```
如果还是无法解决问题,建议检查配置文件是否有误或者查看相关教程和文档以获得更多帮助。
相关问题
activiti7.1.0.m6java代码导入、导出流程
可以使用 Activiti 提供的 API 进行流程的导入和导出,具体实现步骤如下:
1. 导出流程
```java
public void exportProcess(String processDefinitionId, HttpServletResponse response) throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
byte[] buffer = new byte[bpmnStream.available()];
bpmnStream.read(buffer);
bpmnStream.close();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
IOUtils.copy(in, response.getOutputStream());
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + processDefinition.getResourceName());
response.flushBuffer();
}
```
2. 导入流程
```java
public void importProcess(MultipartFile file) throws Exception {
InputStream inputStream = file.getInputStream();
Deployment deployment = repositoryService.createDeployment().addInputStream(file.getOriginalFilename(), inputStream).deploy();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
repositoryService.addCandidateStarterUser(processDefinition.getId(), "userId");
}
```
其中,`exportProcess` 方法用于导出指定流程定义的 BPMN 文件,`importProcess` 方法用于将上传的 BPMN 文件部署到 Activiti 中。需要注意的是,在导入流程时,需要为流程定义指定候选用户或组,以便在启动流程时能够选择合适的用户或组。
Activiti7.1.0.M6中,SequenceFlow标签可以通过扩展BPMNXMLConverter来新增自定义属性
是的,SequenceFlow标签可以通过扩展BPMNXMLConverter来新增自定义属性。
在 Activiti7.1.0.M6 版本中,SequenceFlow 标签可以通过扩展 BPMNXMLConverter 类来新增自定义属性。具体做法如下:
1. 创建一个类,继承自 org.activiti.bpmn.converter.BPMNXMLConverter 类。
2. 重写 convertToXML 方法,在该方法中添加自定义属性。
3. 在 Activiti7 的配置文件中配置自定义的 BPMNXMLConverter 类。
例如,我们可以创建一个 CustomBPMNXMLConverter 类来添加自定义属性,具体代码如下:
```
public class CustomBPMNXMLConverter extends BPMNXMLConverter {
@Override
protected void convertSequenceflow(XMLStreamReader xtr, BpmnModel model, Process activeProcess) throws Exception {
super.convertSequenceflow(xtr, model, activeProcess);
SequenceFlow sequenceFlow = (SequenceFlow) model.getFlowElement(findCurrentFlowElement(xtr));
//添加自定义属性
sequenceFlow.setCustomProperty("myCustomProperty", "customValue");
}
}
```
然后,在 Activiti7 的配置文件中配置 CustomBPMNXMLConverter,具体配置如下:
```
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="customPostBPMNParseListeners">
<list>
<bean class="org.activiti.engine.impl.bpmn.parser.factory.DefaultBpmnParseFactory">
<property name="bpmnParser">
<bean class="org.activiti.bpmn.converter.BpmnXMLConverter">
<property name="converters">
<list>
<bean class="org.activiti.bpmn.converter.StartEventXMLConverter"/>
<bean class="org.activiti.bpmn.converter.EndEventXMLConverter"/>
<bean class="org.activiti.bpmn.converter.SequenceFlowXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ThrowEventXMLConverter"/>
<bean class="org.activiti.bpmn.converter.BusinessRuleTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.MailTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ManualTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ReceiveTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ScriptTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ServiceTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.UserTaskXMLConverter"/>
<bean class="org.activiti.bpmn.converter.CallActivityXMLConverter"/>
<bean class="org.activiti.bpmn.converter.SubProcessXMLConverter"/>
<bean class="org.activiti.bpmn.converter.EventGatewayXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ExclusiveGatewayXMLConverter"/>
<bean class="org.activiti.bpmn.converter.InclusiveGatewayXMLConverter"/>
<bean class="org.activiti.bpmn.converter.ParallelGatewayXMLConverter"/>
<bean class="org.activiti.bpmn.converter.TransactionXMLConverter"/>
<bean class="com.example.CustomBPMNXMLConverter"/> <!-- 添加自定义的 BPMNXMLConverter -->
</list>
</property>
</bean>
</property>
</bean>
</list>
</property>
</bean>
```
这样,我们就可以通过扩展 BPMNXMLConverter 类来新增自定义属性了。
阅读全文