Spring Boot & Thymeleaf with XML Templates

configuration, spring-boot, spring-mvc, thymeleaf

Solution

After trying and failing at various bean defs for viewResolver and related things, I finally got this working with a change to my application.yaml file:

spring:
  thymeleaf:
    suffix: .xml
    content-type: text/xml

For those reading this later, you can do similar with your application.properties file (with dot notation in place of the yaml indentation).

Problem

I have a Spring Boot application with a controller that returns a ModelAndView and Thymeleaf to render templates, where the templates live in /src/main/resources/templates/*.html This works fine, but How can I configure Spring and/or Thymeleaf to look for xml files instead of html? If it helps, I'm using Gradle with the org.springframework.boot:spring-boot-starter-web dependency to set things up. I am currently running the server using a class with a main method.

Original source