Skip to content

Commit c0c32d8

Browse files
committed
Merge pull request #30456 from candrews
* gh-30456: Polish "Make MustacheViewResolver bean back off without Spring MVC" Make MustacheViewResolver bean back off without Spring MVC Closes gh-30456
2 parents 05b7bef + 8cb11b7 commit c0c32d8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.samskivert.mustache.Mustache.Compiler;
2020

21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2122
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
@@ -29,6 +30,7 @@
2930

3031
@Configuration(proxyBeanMethods = false)
3132
@ConditionalOnWebApplication(type = Type.SERVLET)
33+
@ConditionalOnClass(MustacheViewResolver.class)
3234
class MustacheServletWebConfiguration {
3335

3436
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.mustache;
18+
19+
import com.samskivert.mustache.Mustache;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.boot.autoconfigure.AutoConfigurations;
23+
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
24+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Tests for {@link MustacheAutoConfiguration} without Spring MVC on the class path.
30+
*
31+
* @author Andy Wilkinson
32+
*/
33+
@ClassPathExclusions("spring-webmvc-*.jar")
34+
class MustacheAutoConfigurationWithoutWebMvcTests {
35+
36+
@Test
37+
void registerBeansForServletAppWithoutMvc() {
38+
new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(MustacheAutoConfiguration.class))
39+
.run((context) -> {
40+
assertThat(context).hasSingleBean(Mustache.Compiler.class);
41+
assertThat(context).hasSingleBean(MustacheResourceTemplateLoader.class);
42+
});
43+
}
44+
45+
}

0 commit comments

Comments
 (0)