Upgrading to Thymeleaf 3 and Re-Implementing Rich HTML Email in Spring

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Upgrading to Thymeleaf 3 and Re-Implementing Rich HTML Email in Spring

mkez00
Hello all,

i'm going to copy and paste a question I posted this morning to Stack Overflow (http://stackoverflow.com/questions/39615624/upgrading-to-thymeleaf-3-and-re-implementing-rich-html-email-in-spring).  Hoping someone can help me out!

I am migrating my project from Thymeleaf 2 to 3 and I'm having an issue with the email template resolver interfering with my web template resolver.

When we first implemented Thymeleaf we followed this document to allow for email templates and web templates and had no issues (section 4.2):

http://www.thymeleaf.org/doc/articles/springmail.html

During conversion to Thymeleaf 3, I worked with ONLY the one template resolver for HTML templates (using the SpringResourceTemplateResolver) and the conversion was fine. I was able to run my application without any problems and the view templates all rendered without problems.

However, when including the email template resolver (using the ClassLoaderTemplateResolver), the following error occurs when going to any controller endpoint that returns a view:

java.io.FileNotFoundException: ClassLoader resource "thymeleaf/thymeleaf/login.html" does not exist

Which indicates it is trying to load the template from the ClassLoaderTemplateResolver and not the SpringResourceTemplateResolver. In Thymeleaf 2 setting the Order attribute solved this problem but this doesn't appear to work in Thymeleaf 3.

I couldn't find any help in the Thymeleaf 3 documentation for having 2 Template resolvers like there was in Thymeleaf 2 docs.

Any suggestions on how to get this working or documentation that I may have overlooked?
Reply | Threaded
Open this post in threaded view
|

Re: Upgrading to Thymeleaf 3 and Re-Implementing Rich HTML Email in Spring

Zemi
Administrator
Hello,

I am not sure if you're aware that the Rich HTML email project has already been migration to Thymeleaf 3, you can clone it from
  https://github.com/thymeleaf/thymeleafexamples-springmail

I am sure you will find there examples of what you're trying to achieve.

Kind regards,
  Zemi

Reply | Threaded
Open this post in threaded view
|

Re: Upgrading to Thymeleaf 3 and Re-Implementing Rich HTML Email in Spring

Metroids
In reply to this post by mkez00
I have this same setup (a ClassLoaderTemplateResolver for emails and a SpringResourceTemplateResolver for html page templates). I think you need to set this property:

resolver.setCheckExistence(true);

On whichever of your template resolvers happens first, otherwise spring will assume it exists and you will see the error your seeing.