Commit a4d7a775 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent 92100291
...@@ -216,6 +216,7 @@ public class ThymeleafAutoConfiguration { ...@@ -216,6 +216,7 @@ public class ThymeleafAutoConfiguration {
// This resolver acts as a fallback resolver (e.g. like a // This resolver acts as a fallback resolver (e.g. like a
// InternalResourceViewResolver) so it needs to have low precedence // InternalResourceViewResolver) so it needs to have low precedence
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5);
resolver.setCache(this.properties.isCache());
return resolver; return resolver;
} }
......
...@@ -238,6 +238,19 @@ public class ThymeleafAutoConfigurationTests { ...@@ -238,6 +238,19 @@ public class ThymeleafAutoConfigurationTests {
is(instanceOf(GroupingStrategy.class))); 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 @Configuration
@ImportAutoConfiguration({ ThymeleafAutoConfiguration.class, @ImportAutoConfiguration({ ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class }) PropertyPlaceholderAutoConfiguration.class })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment