ERROR: 'ContentNegotiationViewResolver'of Spring 3.0.3 MVC + JSON Portlet

I want to make spring MVC 3.0.3 port using the DispatcherPortlet class. JSON support. So, I added the following configuration in the spring context file.

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

                       text / html                                                    

Without this, if I only use the "InternalResourceViewResolver", then it works fine, and I can use the portlet. But with this bean, I got the following error when starting tomcat.

I googled around and found a link stating that this bean with JSON only works with servlets in the latest spring vesion. please check the link.

http://jira.springframework.org/browse/SPR-7344 (JSON problem for portlets ...)

http://jira.springframework.org/browse/SPR-6932?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel#issue-tabs

Also check the error 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

check 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)
+2
source share
2 answers

ContentNegotiatingViewResolver does not work with portlets, but only with servlets.

Typically, many servlet API classes in Spring have a portlet equivalent, for example

  • org.springframework.web. servlet .HandlerAdapter
  • org.springframework.web. portlet .HandlerAdapter

You must ensure that you are using the correct option — the servlet and portlet APIs are completely incompatible.

, Spring 2.5, (, , ), MVC API API- MVC.

, , , . , ContentNegotiatingViewResolver .

+2

.


 
 

<!-- 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>
0

Source: https://habr.com/ru/post/1752814/


All Articles