我已經包括傑克遜映射在我的POM文件獲得spring mvc 3.1輸出json和xml響應所需的最小數量是多少?
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
也爲XML我包括我的POM文件
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.2</version>
</dependency>
兩個春天OXM和XStream和後續是我的Spring MVC的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<mvc:resources mapping="/static/js/**" location="/static/js/"/>
<mvc:resources mapping="/favicon.ico" location="/favicon.ico"/>
<mvc:annotation-driven />
<context:component-scan base-package="com.xyz.web.controllers"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
每當我試圖讓JSON或XML響應,我得到這個
DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from handler [public com.xyz.web.controllers.User com.xyz.web.controllers.UserController.get(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
任何幫助,非常感謝!
此信息對您有幫助 http://blog.springsource.org/2010/01/25/ajax-simplifications-in-spring-3-0/ – 2012-02-22 02:42:57
好吧,根據那篇文章「json serialization」已啓用當您使用帶有存在於您的類路徑中的Jackson的mvc:註釋驅動配置元素時自動執行「。我相信我符合這兩個標準。 – Bobo 2012-02-22 14:24:29