Spring Boot整合Activiti,查看流程图出现中文乱码问题

时间:2023-01-10 06:42:51

最近研究SpringBoot 整合Activiti时,实现流程图高亮追踪是出现中文乱码问题,找了很多方法,现在把我最后的解决方法提供给大家。

Spring Boot是微服务快速开发框架,强调的是零配置,显然不推荐采用XML配置文件的方式解决。不使用Spring Boot的时候,

是通过下面这种方式就可以解决

①原始解决方式:在Spring配置文件中的

<bean id="processEngineConfiguration"
class="org.activiti.spring.SpringProcessEngineConfiguration">

中加入两行代码:

<property name="activityFontName"
value="宋体"/>

<property name="labelFontName"
value="宋体"/>

配置如下:

<bean id="processEngineConfiguration"

class="org.activiti.spring.SpringProcessEngineConfiguration">

<property name="activityFontName"
value="宋体"/>
<property name="labelFontName"
value="宋体"/>
<property name="dataSource"
ref="dataSource" />
<property name="transactionManager"
ref="transactionManager" />
<property
name="databaseSchemaUpdate" value="true" />
<property
name="mailServerHost" value="localhost" />
<property
name="mailServerPort" value="5025" />
<property
name="jpaHandleTransaction" value="true" />
<property
name="jpaCloseEntityManager" value="true" />
<property
name="jobExecutorActivate" value="false" />
</bean>

②Spring
Boot中我采用的解决办法是,生成流程图的时候设置字体和编码信息解决,如下

public void genPic(String procId) throws
Exception {
ProcessInstance pi =
this.processEngine.getRuntimeService().createProcessInstanceQuery()

.processInstanceId(procId).singleResult();
BpmnModel bpmnModel =
this.processEngine.getRepositoryService().getBpmnModel(pi.getProcessDefinitionId());

List<String> activeIds =
this.processEngine.getRuntimeService().getActiveActivityIds(pi.getId());

ProcessDiagramGenerator p = new DefaultProcessDiagramGenerator();
InputStream is = p.generateDiagram(bpmnModel, "png",
activeIds, Collections.<String> emptyList(), "宋体",
"宋体",
null, 1.0);

File file = new
File("d:\\Download\\process.png");
OutputStream os = new
FileOutputStream(file);

byte[] buffer = new
byte[1024];
int len = 0;
while ((len = is.read(buffer)) !=
-1) {
os.write(buffer, 0, len);
}

os.close();
is.close();
}

转载请注明:http://www.xujin.org