From 4637c2a8f7820e2f499bffc8bbc6d93789f64399 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sat, 22 Mar 2014 14:25:51 +0000 Subject: [PATCH] Accept viewNames and excludedViewNames for ThymeleafViewResolver (via spring.thymeleaf.*). Fixes gh-548 --- .../thymeleaf/ThymeleafAutoConfiguration.java | 4 ++++ .../thymeleaf/ThymeleafAutoConfigurationTests.java | 12 ++++++++++++ 2 files changed, 16 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 b4a137efaa..bf829a6c10 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 @@ -178,6 +178,10 @@ public class ThymeleafAutoConfiguration { resolver.setTemplateEngine(this.templateEngine); resolver.setCharacterEncoding(this.environment.getProperty("encoding", "UTF-8")); + resolver.setExcludedViewNames(this.environment.getProperty( + "excludedViewNames", String[].class)); + resolver.setViewNames(this.environment.getProperty("viewNames", + String[].class)); // Needs to come before any fallback resolver (e.g. a // InternalResourceViewResolver) resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 20); 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 1e7288d754..7f2724a85a 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 @@ -38,6 +38,7 @@ import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.ITemplateResolver; import org.thymeleaf.templateresolver.TemplateResolver; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -85,6 +86,17 @@ public class ThymeleafAutoConfigurationTests { assertEquals("UTF-16", views.getCharacterEncoding()); } + @Test + public void overrideViewNames() throws Exception { + EnvironmentTestUtils.addEnvironment(this.context, + "spring.thymeleaf.viewNames:foo,bar"); + this.context.register(ThymeleafAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + ThymeleafViewResolver views = this.context.getBean(ThymeleafViewResolver.class); + assertArrayEquals(new String[] { "foo", "bar" }, views.getViewNames()); + } + @Test(expected = BeanCreationException.class) public void templateLocationDoesNotExist() throws Exception { EnvironmentTestUtils.addEnvironment(this.context,