spring - Thymeleaf : template might not exist or might not be accessible by any of the configured Template Resolvers -
i have 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 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 launch sending email method have exception :
org.thymeleaf.exceptions.templateinputexception: error resolving template "templateemail.html", template might not exist or might not accessible of configured template resolvers
i dont know if it's because templateengine can't find file (i try tomcat absolute path , /bin directory no way ) or haven't configure right template resolver. thank help. i
it work deleting ".html" in name of template (the file has html extension)
private static final string email_inlineimage_template_name = "templateemail"
Comments
Post a Comment