How do I replace the standard Thymeleaf Context with the reactive SpringWebFluxThymeleafRequestContext?

31 Views Asked by At

I have the following declarative code that uses Spring Boot 3:

public String generatePage(String pageName, Map<String, ? extends Object> parameters) {
        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setSuffix(".html");
        templateResolver.setPrefix("/report-templates/");
        templateResolver.setTemplateMode(TemplateMode.HTML);

        TemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);

        Context context = new Context();

        parameters.forEach((k, v) -> {
            context.setVariable(k, v);
        });

        return templateEngine.process(pageName, context);
    }

I am trying to replace the regular context with the reactive context from thymeleaf-spring. However it is not clear how I would do it and how to use that to pass the parameters to this new context.

Those parameters are coming from a Mono.

0

There are 0 best solutions below