中文乱码主要表现在绘制模型,部署流程定义的时候出现乱码。一开始尝试通过配置文件来解决乱码问题,工程下有一个activiti-custom-context.xml(话说这个好像是5.17版本才有的,配置文件变化还挺大的),按官方说法,是作为自定义配置用的,里面有注释起来的demo,尝试添加配置如下所示:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <!-- 以下两个属性解决流程图中文乱码 --> <property name="activityFontName" value="宋体"></property> <property name="labelFontName" value="宋体"></property> </bean>
protected String activityFontName = "Arial"; protected String labelFontName = "Arial";
然后尝试了此方法:http://www.mossle.com/ask/question.do?id=3 ,还是不行,可能是针对5.17之前的版本有效吧,还是我哪里操作不对了?放弃再找解决方案了,决定直接修改源码。 总共需修改两个类文件,activiti-engine-5.17.0.jar中的ProcessEngineConfiguration和activiti-explorer-5.17.0.jar中的EditorProcessDefinitionDetailPanel,具体修改如下:
ProcessEngineConfiguration.java
protected String activityFontName = "Arial"; protected String labelFontName = "Arial";改为
protected String activityFontName = "宋体"; protected String labelFontName = "宋体";
protected void deployModelerModel(final ObjectNode modelNode) { BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment; try { deployment = repositoryService.createDeployment().name(modelData.getName()) .addString(processName, new String(bpmnBytes,"utf-8"))//加utf-8 .deploy(); ExplorerApp.get().getViewManager().showDeploymentPage(deployment.getId()); }catch (UnsupportedEncodingException e) { // TODO Auto-generated catch } }