In https://www.thymeleaf.org/doc/articles/sayhelloextendingthymeleaf5minutes.html says as example:
Using the hello dialect
Using our new dialect is very easy. This being a Spring MVC application, we just have to add it to our templateEngine bean during configuration.
@Bean
public SpringTemplateEngine templateEngine(){
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setEnableSpringELCompiler(true);
templateEngine.setTemplateResolver(templateResolver());
templateEngine.addDialect(new HelloDialect());
return templateEngine;
}
But templateResolver is not defined and it doesn't say how to make it or what it does.
I try reutilize the default templateEngine adding the custom dialect but can not load the SpringTemplateEngine after the bean config or using a autowired annotation.
I solve this recteating all templateResolver again but it is not defined in the documentation example:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring6.SpringTemplateEngine;
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;
import com.example.demo.dialects.MarkdownDialect;
@Configuration
public class ThymeleafConfig {
@Bean
public SpringResourceTemplateResolver templateResolver() { // For fix
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setPrefix("classpath:/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
// Template engine for thymeleaf
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
// Template engine settings
templateEngine.setEnableSpringELCompiler(true);
templateEngine.setTemplateResolver(this.templateResolver());
// Add custom dialects
templateEngine.addDialect(new MarkdownDialect());
// Return modified template engine
return templateEngine;
}
}
In https://www.thymeleaf.org/doc/articles/sayhelloextendingthymeleaf5minutes.html says as example:
But
templateResolveris not defined and it doesn't say how to make it or what it does.I try reutilize the default
templateEngineadding the custom dialect but can not load theSpringTemplateEngineafter the bean config or using a autowired annotation.I solve this recteating all templateResolver again but it is not defined in the documentation example: