Browse Source

Allow user to opt out of ContentNegotiatingViewResolver

The bean ID for the ContentNegotiatingViewResolver is now
"viewResolver" (it is the *one*). The conditions have been changed
so that a user only has to define a bean of the same name to switch
it off.

Fixes gh-546
pull/543/merge
Dave Syer 12 years ago
parent
commit
373e2c5156
  1. 6
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java
  2. 4
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
  3. 5
      spring-boot-docs/src/main/asciidoc/howto.adoc

6
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

@ -182,9 +182,9 @@ public class ThymeleafAutoConfiguration {
"excludedViewNames", String[].class)); "excludedViewNames", String[].class));
resolver.setViewNames(this.environment.getProperty("viewNames", resolver.setViewNames(this.environment.getProperty("viewNames",
String[].class)); String[].class));
// Needs to come before any fallback resolver (e.g. a // This resolver acts as a fallback resolver (e.g. like a
// InternalResourceViewResolver) // InternalResourceViewResolver) so it needs to have low precedence
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 20); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5);
return resolver; return resolver;
} }

4
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java

@ -179,8 +179,8 @@ public class WebMvcAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(ViewResolver.class) @ConditionalOnBean(ViewResolver.class)
public ContentNegotiatingViewResolver contentNegotiatingViewResolver( @ConditionalOnMissingBean(name = "viewResolver")
BeanFactory beanFactory) { public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver(); ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(beanFactory resolver.setContentNegotiationManager(beanFactory
.getBean(ContentNegotiationManager.class)); .getBean(ContentNegotiationManager.class));

5
spring-boot-docs/src/main/asciidoc/howto.adoc

@ -747,9 +747,8 @@ added.
client. There is a useful client. There is a useful
https://spring.io/blog/2013/06/03/content-negotiation-using-views[blog about `ContentNegotiatingViewResolver`] https://spring.io/blog/2013/06/03/content-negotiation-using-views[blog about `ContentNegotiatingViewResolver`]
that you might like to study to learn more, and also look at the source code for detail. that you might like to study to learn more, and also look at the source code for detail.
Be careful not to define your own `ViewResolver` with id ``viewResolver'' (like the You can switch off the auto-configured
`ContentNegotiatingViewResolver`) otherwise, in that case, your bean will be `ContentNegotiatingViewResolver` by defining a bean named ``viewResolver''.
overwritten, not the other way round.
* If you use Thymeleaf you will also have a `ThymeleafViewResolver` with id * If you use Thymeleaf you will also have a `ThymeleafViewResolver` with id
``thymeleafViewResolver''. It looks for resources by surrounding the view name with a ``thymeleafViewResolver''. It looks for resources by surrounding the view name with a

Loading…
Cancel
Save