From a4d7a7754704bcdee4881b57aac31dff06bd5fa3 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 18 Apr 2016 17:26:13 +0100 Subject: [PATCH] Apply spring.thymeleaf.cache to auto-configured ThymeleafViewResolver Previously, spring.thymeleaf.cache was only applied to auto-configured TemplateResolver. This commit also applies the propery to the auto-configured ThymeleafViewResolver. Closes gh-5395 --- .../thymeleaf/ThymeleafAutoConfiguration.java | 1 + .../thymeleaf/ThymeleafAutoConfigurationTests.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 5db469db485..f4083f997c0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -216,6 +216,7 @@ public class ThymeleafAutoConfiguration { // This resolver acts as a fallback resolver (e.g. like a // InternalResourceViewResolver) so it needs to have low precedence resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); + resolver.setCache(this.properties.isCache()); return resolver; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java index ced271f0fb0..d7f25a50380 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java @@ -238,6 +238,19 @@ public class ThymeleafAutoConfigurationTests { is(instanceOf(GroupingStrategy.class))); } + @Test + public void cachingCanBeDisabled() { + this.context.register(ThymeleafAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.cache:false"); + this.context.refresh(); + assertThat(this.context.getBean(ThymeleafViewResolver.class).isCache(), + is(false)); + TemplateResolver templateResolver = this.context.getBean(TemplateResolver.class); + templateResolver.initialize(); + assertThat(templateResolver.isCacheable(), is(false)); + } + @Configuration @ImportAutoConfiguration({ ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })