我使用下列庫:如何使用GsonHttpMessageConverter獲取oauth標記?
- 彈簧安全oauth2-2.0.9
- 彈簧4.2.1
- GSON - 2.2.4
和配置GsonHttpMessageConverter applicationContext.xml:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.GsonHttpMessageConverter">
<property name="gson" ref="gson"/>
<property name="supportedMediaTypes" value="application/json" />
<property name="prefixJson" value="false"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
加:
<bean id="gsonFactoryBean" class="org.springframework.http.converter.json.GsonFactoryBean">
<property name="dateFormatPattern" value="yyyy'-'MM'-'dd"/>
<property name="disableHtmlEscaping" value="true"/>
<property name="prettyPrinting" value="true"/>
<!-- <property name="gson" ref="gson"/>-->
</bean>
<bean id="gsonBuilder" class="com.google.gson.GsonBuilder">
<property name="dateFormat" value="yyyy'-'MM'-'dd" />
</bean>
默認情況下彈簧的oauth2使用傑克遜轉換器序列化/反序列化JSON。通過包含jackson庫,我無法從Spring TokenEndPoint服務中獲取oauth令牌。當我評論消息轉換器標籤時,我能夠獲得oauth標記。請讓我知道如何使用GsonHttpMessageConverter獲取oauth標記,或者是否有任何其他方式來獲取oauth標記。
當調試GsonHttpMessageConverter代碼時,它拋出HttpMessageNotWritableException,請大家幫忙。看起來OAuth2AccessToken.java的expiration屬性是java.util.Date類型,這可能是配置轉換器的問題。這個轉換器我們需要以這種格式發佈json日期。請幫忙
在此先感謝。
訪問這裏:http://www.programcreek.com/java-api-examples/index.php?api=org.springframework.web.client.RestTemplate – 2016-03-08 12:48:57
的詳細看這個:HTTP ://www.programcreek.com/java-api-examples/index.php source_dir =撰寫-IDM-主/ SRC /主/爪哇/ DE /帕紹/ UNI /秒/撰寫/ ID /核心/服務/安全/uaa/UAAClient.java – 2016-03-08 12:49:16
我認爲問題是與GsonHttpMessageConverter,無法將OAuth2AccessToken轉換爲JSON,因爲它包含過期屬性,該格式與轉換器的指定格式匹配。 – chiku