is it possible to use InternalResourceViewResolver and BeanNameViewResolver together in the same web app?
I mean 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With