最近研究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
