ecbrodie
ecbrodie

Reputation: 11906

Some questions about resolving multiplt Spring View Resolvers

I have a couple questions about Spring MVC View Resolvers. Reference: http://docs.spring.io/spring/docs/4.0.3.RELEASE/spring-framework-reference/htmlsingle/#mvc-viewresolver-chaining

  1. What happens when there is no order property set for a particular view resolver?
  2. What does the document mean by an InternalResourceViewResolver, which is always automatically positioned as the last resolver in the chain? Does it mean that the InternalResourceViewResolver should always be given the highest order as a convention, or maybe Spring implicitly enforces that this resolver must always be loaded last and thus the order property is not required?

Thank you in advance.

Upvotes: 0

Views: 155

Answers (1)

Bart
Bart

Reputation: 17361

What happens when there is no order property set for a particular view resolver?

The collection of ViewResolvers will be sorted using a OrderComparator. If it has no order (does not implement Ordered) it will receive Ordered.LOWEST_PRECEDENCE.

What does the document mean by an InternalResourceViewResolver, which is always automatically positioned as the last resolver in the chain? Does it mean that the InternalResourceViewResolver should always be given the highest order as a convention, or maybe Spring implicitly enforces that this resolver must always be loaded last and thus the order property is not required?

InternalResourceViewResolver is forcefully positioned as last in the chain because it will always return a view no matter if it exists or not rendering any ViewResolver next in the chain unreachable.


http://docs.spring.io/spring/docs/2.5.x/api/org/springframework/web/servlet/view/InternalResourceViewResolver.html

Note: When chaining ViewResolvers, an InternalResourceViewResolver always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists.

Upvotes: 2

Related Questions