springboot整合freemark---解决部署后路径找不到问题

springboot整合freemarker之后,本地跑起来完全没问题,但是打包部署后,报错路径找不到。

HashMap root =new HashMap();
root.put("vo", coverntToVO(policyFailDO));
Configuration config = new Configuration();
config.setDefaultEncoding("UTF-8");
 try {
config.setClassForTemplateLoading(this.getClass(), "/");
Template template = config.getTemplate("templates/policyFail.html", "UTF-8");
String str = FreeMarkerTemplateUtils.processTemplateIntoString(template, root);
SubscribeMsgDO conditon = new SubscribeMsgDO();
conditon.setChannel(policyFailDO.getChannel());
List toMails = subscribeMsgManager.getAllSubscribeInfo(conditon);
mailManager.sendMail("【失败监控】", toMails, str);

之前我是写死路径的,eg:  ./src/resources/templates/policyFail.html

本地跑起来没问题,但是打包部署后测试报错

时间匆忙,就先贴下解决方案,不多说了。

你可能感兴趣的:(sping,boot)