ERROR: 'ContentNegotiatingViewResolver'of Spring 3.0.3 MVC Portlet+JSON
I want to make spring MVC 3.0.3 portlet using DispatcherPortlet class With JSON support. So, i added following configuration in the spring context file.
<bean 开发者_如何学运维class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
text/html
Without this, if i use the 'InternalResourceViewResolver' only then it runs fine and i am able to use the portlet. But with this bean defined, i got the following error on tomcat startup.
I googled around and find a link stating that this bean with JSON only works with servlets in the latest spring vesion. please check the link as well.
http://jira.springframework.org/browse/SPR-7344 (JSON issue for portlets...)
http://jira.springframework.org/browse/SPR-6932?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel#issue-tabs
Also please check the error pasted below. Help me... thanks.
:ERROR:
java.lang.IllegalArgumentException: Object of class [org.springframework.web.portlet.context.PortletRequestAttributes] must be an instance of class org.springframework.web.context.request.ServletRequestAttributes
please check the log
Caused by: java.lang.IllegalArgumentException: Object of class [org.springframework.web.portlet.context.PortletRequestAttributes] must be an instance of class org.springframework.web.context.request.ServletRequestAttributes
at org.springframework.util.Assert.isInstanceOf(Assert.java:337)
at org.springframework.util.Assert.isInstanceOf(Assert.java:319)
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:363)
at org.springframework.web.portlet.DispatcherPortlet.resolveViewName(DispatcherPortlet.java:1110)
at org.springframework.web.portlet.DispatcherPortlet.render(DispatcherPortlet.java:1052)
at org.springframework.web.portlet.DispatcherPortlet.doRenderService(DispatcherPortlet.java:761)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:522)
ContentNegotiatingViewResolver
doesn't work with portlets, only servlets.
As a general rule, many servlet API classes in Spring have a portlet equivalent, e.g.
- org.springframework.web.servlet.HandlerAdapter
- org.springframework.web.portlet.HandlerAdapter
You have to make sure that you use the right one - the servlet and portlet APIs are completely incompatible.
However, since Spring 2.5, the portlet framework has been neglected (probably because it's very rarely used), and newer parts of the servlet MVC API have not been included in the portlet MVC API.
It would seem that if you want to do what you're trying to do, you're going to have to do a lot of it yourself. You might be able to copy some of the code from ContentNegotiatingViewResolver
and related classes.
Check this out. It should work now
<!-- View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/test/testJSp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
精彩评论