Using @someBean in email templates

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Using @someBean in email templates

I followed this tutorial "Rich HTML email in Spring with Thymeleaf" to generate an email using a Thymeleaf template. All is fine, but I can't access the ApplicationContext beans that I use elsewhere in the application.

To be more specific, in my email template I'd like to have something like:

<span th:text="${@myBean.doSomething()}">

where "myBean" is a @Component. Is that possible at all?

In Thymeleaf 2 I used the workaround of adding the ApplicationContext as a bean named "beans", so that I could use a notation like ${beans.myBean.doSomething()}:

ctx.setVariable("beans", new Beans(applicationContext));

This doesn't work anymore in Thymeleaf 3 because the "org.thymeleaf.spring4.context.Beans" class is gone.

More details in this SO post: