Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.4K
Visualizações
Thymeleaf : template might not exist or might not be accessible by any of the configured Template Resolvers

I have this code:

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);
    }
}

I have templateemail.html file under /templates/ directory. when I launch the sending email method I have this exception :

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

I dont know if it's because the templateEngine can't find my file (I try even with tomcat absolute path and /bin directory but no way ) or I haven't configure the right Template Resolver. Thank you very much for your help. I

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

It work now by deleting ".html" in the name of template (the file has the html extension)

private static final String EMAIL_INLINEIMAGE_TEMPLATE_NAME = "templateemail"
over 4 years ago · Santiago Trujillo Relatório

0

Note the non-cross-platform behavior that can occure: on Windows the CamelCase.html template was resolved, but not on Ubuntu linux! There I had to rename it to camelcase.html, all chars in lower case

over 4 years ago · Santiago Trujillo Relatório

0

I had the same issue recently. My problem was that my template had references to other templates that started with /.

For example:

<html ... th:include="/internal/layout-normal :: page">   <-- failed

<html ... th:include="internal/layout-normal :: page">    <-- worked

Both variants worked without problems when I run the application from IntelliJ. However, when packaged and run via java -jar the first line failed.

Removing the / solved the problem for me

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda