V
V
vyn2018-02-19 10:45:27
Java
vyn, 2018-02-19 10:45:27

Why doesn't Tomcat 9 interpret thymeleaf tags?

Good afternoon! Wrote a website in spring. I am deploying a WAR to a server with tomcat 9. However, when browsing the site, tomcat does not interpret thymeleaf tags. They both were and remained in the structure of the html page. An example page is the following:

<body>
    <div th:insert="~{menu.html::menu}"></div>

    <main role="main">

      <div class="jumbotron">
        <div class="container">
        </div>
      </div>

      <div th:insert="~{footer.html::footer}"></div>

MVC configuration is as follows:
@Configuration
@EnableWebMvc
@ComponentScan({ "ru.dev.avtonomki" })
public class WebMVCConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ViewResolver jspViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine(jspTemplateResolver()));
        resolver.setContentType("text/html");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setOrder(1);
        resolver.setViewNames(ArrayUtil.array("*.html"));
        return resolver;
    }

  private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.addDialect(new LayoutDialect(new GroupingStrategy()));
    engine.addDialect(new Java8TimeDialect());
    engine.setTemplateResolver(templateResolver);
    //engine.setTemplateEngineMessageSource(messageSource());
    return engine;
  }

    private ITemplateResolver jspTemplateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("/");
        //resolver.setSuffix(".jsp");
        resolver.setCacheable(false);
        resolver.setTemplateMode(TemplateMode.HTML5);
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("/static/");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new NameFormatter());
    }
}

Why doesn't tomcat interpret thymeleaf tags?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question