Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.4K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda