diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java
index 2e2225f8fca..ebcbbc797c0 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java
@@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.thymeleaf.TemplateProcessingParameters;
@@ -153,6 +154,9 @@ public class ThymeleafAutoConfiguration {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(this.templateEngine);
resolver.setCharacterEncoding("UTF-8");
+ // Needs to come before any fallback resolver (e.g. a
+ // InternalResourceViewResolver)
+ resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 20);
return resolver;
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
index 8a7086632f1..e8221bad169 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
@@ -58,6 +58,7 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link EnableWebMvc Web MVC}.
@@ -110,6 +111,14 @@ public class WebMvcAutoConfiguration {
@Autowired
private ResourceLoader resourceLoader;
+ @ConditionalOnBean(View.class)
+ @ConditionalOnMissingBean(InternalResourceViewResolver.class)
+ @Bean
+ public InternalResourceViewResolver defaultViewResolver() {
+ InternalResourceViewResolver resolver = new InternalResourceViewResolver();
+ return resolver;
+ }
+
@ConditionalOnBean(View.class)
@Bean
public BeanNameViewResolver beanNameViewResolver() {
@@ -124,6 +133,9 @@ public class WebMvcAutoConfiguration {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(beanFactory
.getBean(ContentNegotiationManager.class));
+ // ContentNegotiatingViewResolver uses all the other view resolvers to locate
+ // a view so it should have a high precedence
+ resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return resolver;
}
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
index c0d71bdeae5..648f86ae550 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
@@ -25,7 +25,6 @@ import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
@@ -35,7 +34,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.View;
-import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.AbstractView;
import static org.junit.Assert.assertEquals;
@@ -78,15 +76,6 @@ public class WebMvcAutoConfigurationTests {
assertEquals(6, this.context.getBeanNamesForType(HandlerMapping.class).length);
}
- @Test
- public void viewResolversCreatedIfViewsPresent() throws Exception {
- this.context = new AnnotationConfigEmbeddedWebApplicationContext();
- this.context.register(Config.class, ViewConfig.class,
- WebMvcAutoConfiguration.class);
- this.context.refresh();
- assertEquals(2, this.context.getBeanNamesForType(ViewResolver.class).length);
- }
-
@Configuration
protected static class ViewConfig {
diff --git a/spring-boot-samples/spring-boot-sample-web-static/pom.xml b/spring-boot-samples/spring-boot-sample-web-static/pom.xml
index 1f42294a83c..cef97fa519b 100644
--- a/spring-boot-samples/spring-boot-sample-web-static/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-web-static/pom.xml
@@ -19,6 +19,11 @@
spring-boot-starter-web
${project.version}
+
+ ${project.groupId}
+ spring-boot-starter-actuator
+ ${project.version}
+
${project.groupId}
spring-boot-starter-tomcat