我已經設定了一個 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>"
我認為有兩種選擇:
- 以某種方式關閉 Spring 對 UserInfoTokenServices 的自動檢查
2.使用setMessageConverters向resttemplate添加一個轉換器
我不知道第一個是否可行。至于第二個,我已經制作了一個 XStream MapEntryConverter,但 Resttemplate 想要一個 HttpMessageConverter。
為什么默認情況下 UserInfoTokenServices 需要哈希圖?有替代方法嗎?
uj5u.com熱心網友回復:
通常,您不必創建自己的轉換器,至少對于 JSON/XML - Spring 將根據類路徑上可用的庫來配置它們。
對于提到的格式,您通常需要 Jackson 庫。在您的情況下,它是com.fasterxml.jackson.dataformat:jackson-dataformat-xml依賴項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/482587.html
標籤:春天 弹簧安全 spring-security-oauth2 休息模板 流
