TemplateInputException with Thymeleaf 3.x on Spring Boot 1.5
0 reputation · 23 Oct 2023, 23:22 UTC
0 reputation · 23 Oct 2023, 23:22 UTC
When a Spring Boot 1.5 application declares a direct dependency on Thymeleaf 3.x, startup fails with a TemplateInputException that wraps a NoSuchMethodError for org.thymeleaf.spring5.SpringTemplateEngine.process(...). The error indicates that the Spring Boot 1.5 starter expects the older org.thymeleaf.spring4 integration classes.
• Spring Boot 1.5 is locked by legacy project requirements.
• Thymeleaf 3.x is desired for its new features and bug fixes.
• The Spring Boot 1.5 starter pulls in Thymeleaf 2.x transitively, leading to a classpath conflict.
Developers must decide whether to upgrade Spring Boot to a version that bundles Thymeleaf 3.x, or to downgrade the Thymeleaf dependency to 2.x to maintain compatibility with Spring Boot 1.5.
NoSuchMethodError without breaking auto‑configuration?29275 reputation · 24 Oct 2023, 05:58 UTC
Spring Boot 1.5 does not officially support the thymeleaf-spring5 integration. Spring Boot 2.0+ is the first line that bundles Spring Framework 5 and supports org.thymeleaf.spring5.SpringTemplateEngine. With Spring Boot 1.5 locked, you can use Thymeleaf 3.0.x only with the thymeleaf-spring4 integration. A NoSuchMethodError for org.thymeleaf.spring5.SpringTemplateEngine.process indicates thymeleaf-spring5 is on the classpath.
A direct dependency on Thymeleaf 3.x is pulling in thymeleaf-spring5, while the Spring Boot 1.5 starter brings in thymeleaf-spring4 compatible artifacts. The mixed classpath causes the auto-configured SpringTemplateEngine bean to be created from the wrong module, and template processing fails with TemplateInputException wrapping NoSuchMethodError.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<!-- let the starter manage Thymeleaf core version -->
</exclusions>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.x</version>
</dependency>
Do not declare thymeleaf-spring5. If a library transitively brings it in, add an exclusion for org.thymeleaf:thymeleaf-spring5.
mvn dependency:tree -Dincludes=org.thymeleaf
Expected: thymeleaf 3.0.x and thymeleaf-spring4 present. thymeleaf-spring5 must be absent.
Check the instantiated engine class at runtime or in logs to confirm org.thymeleaf.spring4.SpringTemplateEngine.
Yes, but only with a Spring 4 compatible set. Excluding the starter's transitive Thymeleaf and replacing it with Thymeleaf 3.0.x + thymeleaf-spring4 is safe and preserves auto-configuration. Replacing it with a version that brings thymeleaf-spring5 breaks auto-configuration and produces the NoSuchMethodError. Mixing thymeleaf-spring4 and thymeleaf-spring5 jars on the same classpath can cause classloader conflicts even if startup succeeds.
Missing diagnostic detail that changes the recommendation: what exact Thymeleaf core version and which thymeleaf-spring artifact is present in your dependency tree right now. If you are on Thymeleaf 3.1+ the only safe path on Spring Boot 1.5 is to downgrade to Thymeleaf 3.0.x with thymeleaf-spring4.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.