Using different View resolvers in Spring

SZ khan, modified 15 Years ago. Regular Member Posts: 145 Join Date: 10/31/09 Recent Posts
I have a question. I am using Spring Portlet MVC and it works with InternalResourceViewResolver and BeanNameViewResolver but doesn't work with ResourceBundleViewResolver and XmlViewResolver in a Spring MVC Portlet.

For e.g. if I use this in my *-portlet.xml

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
	 <property name="basename" value="views" />  
	  <property name="order" value="1" />  
	 </bean>


It gives the following error

java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.ResourceBundleViewResolver@1164deb] does not run within a ServletContext. Make sure the object is fully configured!

If I add the following in my web.xml

<context-param>
               <param-name>contextConfigLocation</param-name>
               <param-value>/WEB-INF/context-test/*-portlet.xml</param-value>
       </context-param>
       <listener>
               <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>


then I get the following error.

Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
I am using Service Builder in my portlet.

Any ideas?...
Thanks
thumbnail
David H Nebinger, modified 15 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
SZ khan:
<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
	 <property name="basename" value="views" />  
	  <property name="order" value="1" />  
	 </bean>


It gives the following error

java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.ResourceBundleViewResolver@1164deb] does not run within a ServletContext. Make sure the object is fully configured!


The error is accurate. You're trying to use a servlet (see the package for the ResourceBundleViewResolver?) within the scope of a portlet. In a portlet there is no ServletContext, there is a PortletContext.

The good news is that you can override the ResourceBundleViewResolver to make it PortletContext-capable. Most of the time when the ServletContext is being referenced, you can replace that with PortletContext, but without digging into the code I really can't tell you how much work you're going to be doing to adapt it correctly.