Я использую Spring
+ Freemarker
в качестве шаблона для отправки писем, но каждый раз, когда я пытаюсь отправить письмо, я получаю сообщение
freemarker.template.TemplateNotFoundException: Template not found for name "template.ftl".
Мой код следующий:
// Configuration - AppConfig.java
@Bean
public freemarker.template.Configuration freeMarkerConfigurationFactory() throws Exception{
FreeMarkerConfigurationFactory fmcf = new FreeMarkerConfigurationFactory();
fmcf.setTemplateLoaderPath("classpath:/META-INF/freemarker/");
fmcf.setPreferFileSystemAccess(false);
fmcf.setDefaultEncoding("UTF-8");
return fmcf.createConfiguration();
}
Служба отправки почты
@Override
@Async
public void sendActivationMail(User user, HttpServletRequest request, String restorePasswordId) throws MailException, MessagingException, GetDataException {
MimeMessage mimeMessage = mailSender.createMimeMessage();
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
mimeMessage.setSubject(SOFTWARE_NAME + " - Activation");
mimeMessage.setHeader("content-type", "text/html");
Map map = new HashMap();
map.put("link", ServletUtility.getCompleteAdress(request)+"/auth/confirm/"+restorePasswordId);
try{
mimeMessage.setContent(FreeMarkerTemplateUtils.processTemplateIntoString(freeMakerConfiguration.getTemplate("template.ftl"), map),
"text/html; charset=utf-8");
}catch(Exception e){e.printStackTrace();}
mailSender.send(mimeMessage);
}
А это мое дерево каталогов:
src
-main
--java
--- it.navium.secutor
----AppConfig.java
--resources
--webapp
---META-INF
----freemarker
-----template.ftl