[英]spring batch exception Cannot construct java.util.Map$Entry
[英]Resttemplate Oauth2 Spring Userinfo cannot convert xml to java.util.map
我已經設置了一個 Oath2 resttemplate 客戶端。當它通過遠程服務進行身份驗證返回時,它會嘗試將 Userinfo 從 XML 轉換為 util.Map 並死於
o.s.b.a.s.o.r.UserInfoTokenServices - Could not fetch user details: class org.springframework.web.client.UnknownContentTypeException, Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [application/xml;charset=UTF-8]
它接收的 XML 如下:
"<root><userinfo userid="Userxxx " lastname="xxx" firstname="xxx" /></root>"
我認為有兩種選擇:
2.使用setMessageConverters向resttemplate添加一個轉換器
我不知道第一個是否可行。 至於第二個,我已經制作了一個 XStream MapEntryConverter,但 Resttemplate 想要一個 HttpMessageConverter。
為什么默認情況下 UserInfoTokenServices 需要哈希圖? 有替代方法嗎?
通常,您不必創建自己的轉換器,至少對於 JSON/XML - Spring 將根據類路徑上可用的庫來配置它們。
對於提到的格式,您通常需要 Jackson 庫。 在您的情況下,它是com.fasterxml.jackson.dataformat:jackson-dataformat-xml
依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.