0

这花了我很多努力才弄清楚,所以我将回答下面的问题。这个答案不使用注释,也不需要创建额外的类。

4

1 回答 1

1

你把它放在你的spring xml上下文配置中:

<?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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

...

<bean id="jacksonMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
    <property name="dateFormat">
        <bean class="java.text.SimpleDateFormat">
            <constructor-arg type="java.lang.String" value="yyyyMMdd'T'HHmmss.SSSZ"/>
        </bean>
    </property>
</bean>
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"
      p:mapper-ref="jacksonMapper"/>

...

     <jaxrs:providers>
        <ref bean="jsonProvider"></ref>
     </jaxrs:providers>
  </jaxrs:server>
于 2015-02-13T21:19:42.407 回答