Using thymeleaf without Spring, Servlet Container, Controller specific logic
See original GitHub issueI have missed about 30 minutes trying to figure out how to generate email HTML body from my service. This is a scheduled task, not an API call - means no controllers and Spring integrations. I have raw java and I want to process single *.html file with Thymeleaf. How to do that?
In other words, I need Thymeleaf analogy for Velocity example:
VelocityEngine ve = new VelocityEngine();
ve.init();
Template t = ve.getTemplate( "helloworld.vm" );
VelocityContext context = new VelocityContext();
context.put("name", "World");
StringWriter writer = new StringWriter();
t.merge( context, writer );
P.S. I’ve read this issue, it doesn’t provide an answer. Both Thymeleaf doc and thymeleafexamples-gtvg are bound to controller logic, resolvers and other stuff I do not need.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Tutorial: Using Thymeleaf
The main goal of Thymeleaf is to provide an elegant and highly-maintainable way of creating templates. To achieve this, it builds on the...
Read more >Spring MVC Data and Thymeleaf - Baeldung
In this tutorial, we'll talk about different ways to access Spring MVC data using Thymeleaf. We'll start by creating an email template using...
Read more >B Spring MVC and Thymeleaf Template Engine
If you are not familiar with Spring MVC, refer to the Spring MVC ... Besides, the controller also returns a logical view name...
Read more >Web on Servlet Stack - Spring
The DispatcherServlet , as any Servlet , needs to be declared and mapped according to the Servlet specification by using Java configuration or...
Read more >Spring Boot Thymeleaf View - Javatpoint
Note: Do not forget to implement the following in the template file. · package com.javatpoint; · import org.springframework.boot.SpringApplication; · import org.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those that may find this later on (like I did), I have a small working example.
pom dependencies
resources/templates/greeting.html
Application.java in hello package
Here is a related Stack Overflow post: How to use Thymeleaf to make only a simple Java app (without Spring).
Borrowing from @huffstler solution above for Java, here is the same solution for Kotlin: