spring boot 调用 thymeleaf 模板失败

tero17

我遇到了这个错误,我在堆栈上搜索了与我相同的问题,我发现我不应该在调用它时放置 .html 但我遇到了同样的错误:

`Caused by: org.thymeleaf.exceptions.TemplateInputException: Error resolving template "orderConfirmationEmailTemplate", template might not exist or might not be accessible by any of the configured Template Resolver`s

我的邮件构造函数:

@Component
public class MailConstructor {

    @Autowired
    private Environment env;

    @Autowired
    private TemplateEngine templateEngine;

    public SimpleMailMessage constructNewUserEmail(User user, String password) {
        String message="\nPlease use the following credentials to log in and edit your personal information including your own password."
                + "\nUsername:"+user.getUsername()+"\nPassword:"+password;

        SimpleMailMessage email = new SimpleMailMessage();
        email.setTo(user.getEmail());
        email.setSubject("Le's Bookstore - New User");
        email.setText(message);
        email.setFrom(env.getProperty("support.email"));
        return email;
    }

    public MimeMessagePreparator constructOrderConfirmationEmail (User user, Order order, Locale locale) {
        Context context = new Context();
        context.setVariable("order", order);
        context.setVariable("user", user);
        context.setVariable("cartItemList", order.getCartItemList());
        String text = templateEngine.process("orderConfirmationEmailTemplate.html", context);

        MimeMessagePreparator messagePreparator = new MimeMessagePreparator() {
            @Override
            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper email = new MimeMessageHelper(mimeMessage);
                email.setTo(user.getEmail());
                email.setSubject("Order Confirmation - "+order.getId());
                email.setText(text,true);
                email.setFrom(new InternetAddress("[email protected]"));
            }
        };

        return messagePreparator;
    }

我从休息服务中调用它:

mailSender.send(mailConstructor.constructOrderConfirmationEmail(user, order, Locale.ENGLISH));

    shoppingCartService.clearShoppingCart(shoppingCart);

我将文件 .html 放在项目中的包下

在此处输入图片说明

tero17

实际上我的配置放在我的问题中,我只是将 .html 文件放在资源下名为模板的文件下,它可以发送邮件,spring boot 显然是自动配置了这个路径而不配置 templateResolver

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Spring Boot中从Thymeleaf模板调用方法?

来自分类Dev

Spring Boot Thymeleaf Ajax 调用

来自分类Dev

Spring Boot-Thymeleaf模板

来自分类Dev

Spring Boot和Thymeleaf与XML模板

来自分类Dev

Spring Boot-Thymeleaf模板-多个解析器

来自分类Dev

Spring Boot和Thymeleaf:找不到HTML模板

来自分类Dev

Spring Boot + Thymeleaf css 不适用于模板

来自分类Dev

Spring Boot,Thymeleaf和@Controller

来自分类Dev

Spring Boot Thymeleaf相对网址

来自分类Dev

Spring Boot-Thymeleaf与JQuery?

来自分类Dev

Spring Boot,使用Thymeleaf发行

来自分类Dev

Spring Boot 和 Thymeleaf 的问题

来自分类Dev

Spring Boot使用Thymeleaf作为模板发送电子邮件-配置不起作用

来自分类Dev

将自定义Thymeleaf模板解析器添加到Spring Boot

来自分类Dev

如何在 Spring Boot 中返回模板(thymeleaf)并将其解析到特定端点

来自分类Dev

模板 Thymeleaf 的 Spring 映射资源

来自分类Dev

Spring Thymeleaf 无法解析模板

来自分类Dev

部署 WAR 时 Spring-Boot 模板解析失败

来自分类Dev

如何使用Spring Boot更新ThymeLeaf

来自分类Dev

Spring Boot + thymeleaf:登录用户

来自分类Dev

字符串格式Thymeleaf Spring Boot

来自分类Dev

Spring Boot + Thymeleaf的@WebAppConfiguration和@ContextConfiguration

来自分类Dev

Spring Boot Security + Thymeleaf:缺少IProcessorDialect类

来自分类Dev

无法使用 Spring Boot thymeleaf 加载图像

来自分类Dev

Thymeleaf Spring boot - 输入本地日期

来自分类Dev

使用Spring Boot 1.3,当在Netbeans中进行更改时,spring-boot-devtools和Thymeleaf模板将不会实时重新加载

来自分类Dev

Spring Boot登录失败

来自分类Dev

Spring-Boot + Spring-MVC + Thymeleaf + Apache Tiles

来自分类Dev

Spring Boot:“创建名为 baseConfig 的 bean 时出错:调用 init 方法失败”NPE

Related 相关文章

  1. 1

    如何在Spring Boot中从Thymeleaf模板调用方法?

  2. 2

    Spring Boot Thymeleaf Ajax 调用

  3. 3

    Spring Boot-Thymeleaf模板

  4. 4

    Spring Boot和Thymeleaf与XML模板

  5. 5

    Spring Boot-Thymeleaf模板-多个解析器

  6. 6

    Spring Boot和Thymeleaf:找不到HTML模板

  7. 7

    Spring Boot + Thymeleaf css 不适用于模板

  8. 8

    Spring Boot,Thymeleaf和@Controller

  9. 9

    Spring Boot Thymeleaf相对网址

  10. 10

    Spring Boot-Thymeleaf与JQuery?

  11. 11

    Spring Boot,使用Thymeleaf发行

  12. 12

    Spring Boot 和 Thymeleaf 的问题

  13. 13

    Spring Boot使用Thymeleaf作为模板发送电子邮件-配置不起作用

  14. 14

    将自定义Thymeleaf模板解析器添加到Spring Boot

  15. 15

    如何在 Spring Boot 中返回模板(thymeleaf)并将其解析到特定端点

  16. 16

    模板 Thymeleaf 的 Spring 映射资源

  17. 17

    Spring Thymeleaf 无法解析模板

  18. 18

    部署 WAR 时 Spring-Boot 模板解析失败

  19. 19

    如何使用Spring Boot更新ThymeLeaf

  20. 20

    Spring Boot + thymeleaf:登录用户

  21. 21

    字符串格式Thymeleaf Spring Boot

  22. 22

    Spring Boot + Thymeleaf的@WebAppConfiguration和@ContextConfiguration

  23. 23

    Spring Boot Security + Thymeleaf:缺少IProcessorDialect类

  24. 24

    无法使用 Spring Boot thymeleaf 加载图像

  25. 25

    Thymeleaf Spring boot - 输入本地日期

  26. 26

    使用Spring Boot 1.3,当在Netbeans中进行更改时,spring-boot-devtools和Thymeleaf模板将不会实时重新加载

  27. 27

    Spring Boot登录失败

  28. 28

    Spring-Boot + Spring-MVC + Thymeleaf + Apache Tiles

  29. 29

    Spring Boot:“创建名为 baseConfig 的 bean 时出错:调用 init 方法失败”NPE

热门标签

归档