Spring and view resolvers
is it possible to use InternalResourceViewResolver and BeanNameViewResolver together in the same web app?
I mean开发者_StackOverflow中文版 InternalResourceViewResolver to resolve my jsp.
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
and instead BeanNameViewResolver to resolve my excel (I need to pass the url).
Bye. Thanks
You can have as many view resolvers in your context as you like, Spring will go over them one by one until it fins one that resolves the view.
There is one big caveat, though:
Note: When chaining
ViewResolvers
, anInternalResourceViewResolver
always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists.
This is a "flaw" with the servlet API, since the InternalResourceViewResolver
has no way of knowing if the resource exists before actually trying it.
So make sure your BeanNameViewResolver
is defined before the InternalResourceViewResolver
, or explicitly specify the order
property on each one.
Yes, you can combine multiple resolvers. Spring iterates over them and uses the first resolver which is able to resolve the given name. You can also set the order
property in resolvers to specify the order of iteration.
精彩评论