Skip to content

Commit a4d7a77

Browse files
committed
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
1 parent 9210029 commit a4d7a77

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public ThymeleafViewResolver thymeleafViewResolver() {
216216
// This resolver acts as a fallback resolver (e.g. like a
217217
// InternalResourceViewResolver) so it needs to have low precedence
218218
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5);
219+
resolver.setCache(this.properties.isCache());
219220
return resolver;
220221
}
221222

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfigurationTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ public void layoutDialectCanBeCustomized() throws Exception {
238238
is(instanceOf(GroupingStrategy.class)));
239239
}
240240

241+
@Test
242+
public void cachingCanBeDisabled() {
243+
this.context.register(ThymeleafAutoConfiguration.class,
244+
PropertyPlaceholderAutoConfiguration.class);
245+
EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.cache:false");
246+
this.context.refresh();
247+
assertThat(this.context.getBean(ThymeleafViewResolver.class).isCache(),
248+
is(false));
249+
TemplateResolver templateResolver = this.context.getBean(TemplateResolver.class);
250+
templateResolver.initialize();
251+
assertThat(templateResolver.isCacheable(), is(false));
252+
}
253+
241254
@Configuration
242255
@ImportAutoConfiguration({ ThymeleafAutoConfiguration.class,
243256
PropertyPlaceholderAutoConfiguration.class })

0 commit comments

Comments
 (0)