gpt4 book ai didi

spring - thymeleaf : template might not exist or might not be accessible by any of the configured Template Resolvers

转载 作者:行者123 更新时间:2023-11-28 21:48:44 28 4
gpt4 key购买 nike

我有这个代码:

private static final String EMAIL_INLINEIMAGE_TEMPLATE_NAME = "templateemail.html";

@Bean
public TemplateEngine emailTemplateEngine() {
templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(this.htmlTemplateResolver());
)

templateEngine.setTemplateEngineMessageSource(this.messageSource);
return templateEngine;
}

private static ITemplateResolver htmlTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(Integer.valueOf(0));
templateResolver.setPrefix("classpath:/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateResolver.DEFAULT_TEMPLATE_MODE);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
return templateResolver;
}


public void sendEmail(String emailAddress, String title, String body, Locale local, String image) {
if (Boolean.parseBoolean(isEmailServiceActivated)) {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper mailMsg = new MimeMessageHelper(mimeMessage);
try {
mailMsg.setFrom(EMAIL_USERNAME);
mailMsg.setTo(emailAddress);
mailMsg.setSubject(title);

// Prepare the evaluation context
ctx.setLocale(local);
ctx.setVariable("imageHeaderResourceName", HEADER_LOGO_IMAGE);
ctx.setVariable("body", body);

ctx.setVariable("imageResourceName", image);

final String htmlContent = this.templateEngine.process(new ClassPathResource(EMAIL_INLINEIMAGE_TEMPLATE_NAME).getPath(), ctx);
mailMsg.setText(htmlContent, true );

mailMsg.addInline(HEADER_LOGO_IMAGE, new ClassPathResource(HEADER_LOGO_IMAGE ) , PNG_MIME);
mailMsg.addInline(image, new ClassPathResource(image) , PNG_MIME);

} catch (MessagingException e) {
e.printStackTrace();
}

mailSender.send(mimeMessage);
}
}

我在/templates/目录下有 templateemail.html 文件。当我启动发送电子邮件方法时出现此异常:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "templateemail.html", template might not exist or might not be accessible by any of the configured Template Resolvers

我不知道是不是因为 templateEngine 找不到我的文件(我什至尝试使用 tomcat 绝对路径和/bin 目录但没有办法)或者我没有配置正确的模板解析器。非常感谢您的帮助。我

最佳答案

它现在通过删除模板名称中的“.html”来工作(文件具有 html 扩展名)

private static final String EMAIL_INLINEIMAGE_TEMPLATE_NAME = "templateemail"

关于spring - thymeleaf : template might not exist or might not be accessible by any of the configured Template Resolvers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43280097/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com