How to locate Thymeleaf template from spring boot

前端 未结 5 1041
梦谈多话
梦谈多话 2021-01-02 23:56

I am trying to follow this tutorial at http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html to learn how to send responses to Thymeleaf template. But I get this er

相关标签:
5条回答
  • 2021-01-03 00:23

    2 things here : 1. If you are using Maven, and I assume no customizations to folder names. Then the folder name should be src instead of source. 2. Once the folder has been renamed move your templates into 'templates' folder inside src/resources this should run fine.

    0 讨论(0)
  • 2021-01-03 00:26

    For Thymeleaf template files put in folder src/main/resources/templates/ and it will work for you also do check out http://www.mkyong.com/spring-boot/spring-boot-hello-world-example-thymeleaf/ . Hope you will find it easy to kick start thymeleaf with spring boot.

    0 讨论(0)
  • 2021-01-03 00:32

    The default directory location for thymeleaf templates is:

    src/main/resources/templates
    

    The other paths are standard conventions for Spring Boot.

    0 讨论(0)
  • 2021-01-03 00:36

    Spring Boot includes auto-configuration support for the thymeleaf templating engines, your templates will be picked up automatically from src/main/resources/templates.

    if you are customize you template location then use below thymeleaf property configuration available in Spring Boot.

    • spring.thymeleaf.check-template=true # Check that the template exists before rendering it.

    • spring.thymeleaf.check-template-location=true # Check that the templates location exists.

    • spring.thymeleaf.enabled=true # Enable MVC Thymeleaf view resolution.

    • spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.

    • spring.thymeleaf.suffix=.html # Suffix that gets appended to view names when building a URL.

    0 讨论(0)
  • 2021-01-03 00:40

    I had the same problem with Spring boot + Gradle and these are the steps that I followed to resolve it:

    1. Print out the classpath

    2. Once I established that the resources folder was not being included in the classpath, I reloaded the application from disk:

    1. Gradle clean the project
    0 讨论(0)
提交回复
热议问题