Merge branch '2.7.x'

pull/30328/merge
Andy Wilkinson 3 years ago
commit f3f5a87af4

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.mustache;
import com.samskivert.mustache.Mustache.Compiler; import com.samskivert.mustache.Mustache.Compiler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.web.reactive.result.view.MustacheViewResolver; import org.springframework.boot.web.reactive.result.view.MustacheViewResolver;
@ -32,6 +33,7 @@ class MustacheReactiveWebConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true)
MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) { MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) {
MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler);
resolver.setPrefix(mustache.getPrefix()); resolver.setPrefix(mustache.getPrefix());

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.mustache;
import com.samskivert.mustache.Mustache.Compiler; import com.samskivert.mustache.Mustache.Compiler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.web.servlet.view.MustacheViewResolver; import org.springframework.boot.web.servlet.view.MustacheViewResolver;
@ -32,6 +33,7 @@ class MustacheServletWebConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.mustache", name = "enabled", matchIfMissing = true)
MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) { MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, MustacheProperties mustache) {
MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler);
mustache.applyToMvcViewResolver(resolver); mustache.applyToMvcViewResolver(resolver);

@ -46,6 +46,16 @@ class MustacheAutoConfigurationTests {
}); });
} }
@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 @Test
void registerCompilerForServletApp() { void registerCompilerForServletApp() {
configure(new WebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class) configure(new WebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)
@ -68,6 +78,17 @@ class MustacheAutoConfigurationTests {
}); });
} }
@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 @Test
void registerCompilerForReactiveApp() { void registerCompilerForReactiveApp() {
configure(new ReactiveWebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class) configure(new ReactiveWebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)

Loading…
Cancel
Save