Reputation: 11906
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
order
property set for a particular view resolver?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
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.
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