From 4248665fcdb3128c33f6f4cf7ac5626bc7ecab5b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 1 May 2014 21:36:44 +0100 Subject: [PATCH] Remove freemarkerConfiguration bean Remove `freemarkerConfiguration` from the FreeMarkerAutoConfiguration since it should not be needed for most applications. The previous code also caused problems since it included a @ConditionalOnBean annotation on a bean that was created in the same configuration. --- .../freemarker/FreeMarkerAutoConfiguration.java | 10 ---------- .../freemarker/FreeMarkerAutoConfigurationTests.java | 6 +++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java index d25b322d64..856428ba98 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java @@ -25,7 +25,6 @@ import javax.servlet.Servlet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication; @@ -42,7 +41,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean; import org.springframework.util.Assert; -import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; @@ -145,14 +143,6 @@ public class FreeMarkerAutoConfiguration implements EnvironmentAware { return freeMarkerConfigurer; } - @Bean - @ConditionalOnBean(FreeMarkerConfigurer.class) - @ConditionalOnMissingBean - public freemarker.template.Configuration freemarkerConfiguration( - FreeMarkerConfig configurer) { - return configurer.getConfiguration(); - } - @Bean @ConditionalOnMissingBean(name = "freeMarkerViewResolver") public FreeMarkerViewResolver freeMarkerViewResolver() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java index 38be24babb..0291ecb5b2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java @@ -191,10 +191,10 @@ public class FreeMarkerAutoConfigurationTests { public void renderTemplate() throws Exception { this.context.register(FreeMarkerAutoConfiguration.class); this.context.refresh(); - freemarker.template.Configuration freemarker = this.context - .getBean(freemarker.template.Configuration.class); + FreeMarkerConfigurer freemarker = this.context + .getBean(FreeMarkerConfigurer.class); StringWriter writer = new StringWriter(); - freemarker.getTemplate("message.ftl").process(this, writer); + freemarker.getConfiguration().getTemplate("message.ftl").process(this, writer); assertTrue("Wrong content: " + writer, writer.toString().contains("Hello World")); }