SPRINGMVC mixed use of multiple view configuration issues

Source: Internet
Author: User
Tags json mixed

Use the Contentnegotiatingviewresolver in the SPRINGMVC configuration file to try the parser, configured as follows

<!--respond to different view requests depending on the client--<bean class= "	Org.springframework.web.servlet.view.ContentNegotiatingViewResolver "> <span style=" White-space:pre "> </span><!--set to true to ignore support for the Accept header--<property name= "Ignoreacceptheader" value= "true"/> < Property Name= "Defaultcontenttype" value= "text/html"/> <!--extension to mimetype Map--<property name= " MediaTypes "> <span style=" white-space:pre "> </span><map> <entry key=" JSON "value=" Application/json "/> <entry key=" xml "value=" Application/xml "/> </map> </property> <prop Erty name= "Favorparameter" value= "false"/> <property name= "viewresolvers" > <list> <bean class= "or G.springframework.web.servlet.view.beannameviewresolver "/> <bean class=" Org.springframework.web.servlet.view.InternalResourceViewResolver "p:prefix="/jsp/"p:suffix=". jsp "/> <bean Class= "Org.springframework.web.servlet.view.velocity. Velocitylayoutviewresolver "> <property name=" suffix "> <value>.vm</value> &LT;/PROPERTY&G
				T <property name= "Datetoolattribute" > <value>dateTool</value> </property> <property Name= "Toolboxconfiglocation" > <value>/WEB-INF/vmtools/toolbox.xml</value> </property> &L T;property name= "ContentType" > <value>text/html;charset=UTF-8</value> </property> </be an> </list> </property> <property name= "Defaultviews" > <list> <!--for application/ JSON--<bean class= "Org.springframework.web.servlet.view.json.MappingJacksonJsonView"/> <!--for app Lication/xml-<!--<bean class= "Org.springframework.web.servlet.view.xml.MarshallingView" >
<span style= "White-space:pre" >					</span><property name= "Marshaller" >
<span style= "White-space:pre" >						</span><bean class= " Org.springframework.oxm.xstream.XStreamMarshaller "/> 
					</property>
<span style= "White-space:pre" >				</span></bean>
		</list>
	</property >
</bean>

In the Viewresolvers attribute above, there are also Internalresourceviewresolver and velocitylayoutviewresolver two parsers. If the velocity template is used in the project, SPRINGMCV will choose to use Internalresourceviewresolver and ignore Velocitylayoutviewresolver, which causes render to fail ....

There are two solutions:

1. Do not use Contentnegotiatingviewresolver, configure the view resolver separately, and set order familiarity, Ensure Velocitylayoutviewresolver priority is greater than internalresourceviewresolver

2. Implement an arbitration parser similar to contentnegotiatingviewresolver.


If anything is wrong, please correct me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.