When i create a pdf from this html file everything works perfectly the first time and creates the pdf to my local machine. But when i create it again it returns this error "Template engine has already been initialized (probably because it has already been executed or a fully-built Configuration object has been requested from it. At this state, no modifications on its configuration are allowed." If i restart my local application server it works again the first time. I've also tried to clear the cache using templateEngine.clearTemplateCache().
It looks like when i run it the second time its using the cached template resolver.
@Service
public class LetterService {
@Autowired
private TemplateEngine templateEngine;
private String processPdfTemplate(Map<String, Object> variables) {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateEngine.setTemplateResolver(templateResolver);
Context context = new Context();
context.setVariables(variables);
context.setLocale(Locale.getDefault());
return templateEngine.process("index", context);
}
}