Skip to content

Commit f3f5a87

Browse files
committed
Merge branch '2.7.x'
2 parents 4b4f3be + fee3b89 commit f3f5a87

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import com.samskivert.mustache.Mustache.Compiler;
2020

2121
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
2425
import org.springframework.boot.web.reactive.result.view.MustacheViewResolver;
@@ -32,6 +33,7 @@ class MustacheReactiveWebConfiguration {
3233

3334
@Bean
3435
@ConditionalOnMissingBean
36+
@ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true)
3537
MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) {
3638
MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler);
3739
resolver.setPrefix(mustache.getPrefix());

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import com.samskivert.mustache.Mustache.Compiler;
2020

2121
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
2425
import org.springframework.boot.web.servlet.view.MustacheViewResolver;
@@ -32,6 +33,7 @@ class MustacheServletWebConfiguration {
3233

3334
@Bean
3435
@ConditionalOnMissingBean
36+
@ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true)
3537
MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) {
3638
MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler);
3739
mustache.applyToMvcViewResolver(resolver);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ void registerBeansForServletApp() {
4646
});
4747
}
4848

49+
@Test
50+
void servletViewResolverCanBeDisabled() {
51+
configure(new WebApplicationContextRunner()).withPropertyValues("spring.mustache.enabled=false")
52+
.run((context) -> {
53+
assertThat(context).hasSingleBean(Mustache.Compiler.class);
54+
assertThat(context).hasSingleBean(MustacheResourceTemplateLoader.class);
55+
assertThat(context).doesNotHaveBean(MustacheViewResolver.class);
56+
});
57+
}
58+
4959
@Test
5060
void registerCompilerForServletApp() {
5161
configure(new WebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)
@@ -68,6 +78,17 @@ void registerBeansForReactiveApp() {
6878
});
6979
}
7080

81+
@Test
82+
void reactiveViewResolverCanBeDisabled() {
83+
configure(new ReactiveWebApplicationContextRunner()).withPropertyValues("spring.mustache.enabled=false")
84+
.run((context) -> {
85+
assertThat(context).hasSingleBean(Mustache.Compiler.class);
86+
assertThat(context).hasSingleBean(MustacheResourceTemplateLoader.class);
87+
assertThat(context).doesNotHaveBean(
88+
org.springframework.boot.web.reactive.result.view.MustacheViewResolver.class);
89+
});
90+
}
91+
7192
@Test
7293
void registerCompilerForReactiveApp() {
7394
configure(new ReactiveWebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)

0 commit comments

Comments
 (0)