diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java index 4aa926fafa3d..729fb82b55b1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.samskivert.mustache.Mustache.Compiler; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.web.reactive.result.view.MustacheViewResolver; @@ -32,6 +33,7 @@ class MustacheReactiveWebConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true) MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) { MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); resolver.setPrefix(mustache.getPrefix()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java index 884a019ecd1f..0ff0462802a4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.samskivert.mustache.Mustache.Compiler; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.web.servlet.view.MustacheViewResolver; @@ -32,6 +33,7 @@ class MustacheServletWebConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true) MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) { MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); mustache.applyToMvcViewResolver(resolver); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java index 2960eb96bf6f..a3669c093088 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java @@ -46,6 +46,16 @@ void registerBeansForServletApp() { }); } + @Test + void servletViewResolverCanBeDisabled() { + configure(new WebApplicationContextRunner()).withPropertyValues("spring.mustache.enabled=false") + .run((context) -> { + assertThat(context).hasSingleBean(Mustache.Compiler.class); + assertThat(context).hasSingleBean(MustacheResourceTemplateLoader.class); + assertThat(context).doesNotHaveBean(MustacheViewResolver.class); + }); + } + @Test void registerCompilerForServletApp() { configure(new WebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class) @@ -68,6 +78,17 @@ void registerBeansForReactiveApp() { }); } + @Test + void reactiveViewResolverCanBeDisabled() { + configure(new ReactiveWebApplicationContextRunner()).withPropertyValues("spring.mustache.enabled=false") + .run((context) -> { + assertThat(context).hasSingleBean(Mustache.Compiler.class); + assertThat(context).hasSingleBean(MustacheResourceTemplateLoader.class); + assertThat(context).doesNotHaveBean( + org.springframework.boot.web.reactive.result.view.MustacheViewResolver.class); + }); + } + @Test void registerCompilerForReactiveApp() { configure(new ReactiveWebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)