commit
fee3b89b1b
|
@ -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 @@ package org.springframework.boot.autoconfigure.mustache;
|
|||
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());
|
||||
|
|
|
@ -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 @@ package org.springframework.boot.autoconfigure.mustache;
|
|||
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);
|
||||
|
|
|
@ -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
|
||||
void registerCompilerForServletApp() {
|
||||
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
|
||||
void registerCompilerForReactiveApp() {
|
||||
configure(new ReactiveWebApplicationContextRunner()).withUserConfiguration(CustomCompilerConfiguration.class)
|
||||
|
|
Loading…
Reference in New Issue