我有一个应用程序使用Spring Source OAuth2作为客户端从资源服务器检索用户数据并创建本地用户.当OAuth2ClientContextFilter尝试检索令牌时,我不断收到错误:
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [org.springframework.security.oauth2.common.OAuth2AccessToken] and content type [application/x-javascript;charset=utf-8]
Run Code Online (Sandbox Code Playgroud)
我理解默认的MediaType是'application/json',所以我尝试像这样自定义MappingJacksonHttpMessageConverter:
<bean id="jacksonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg value="application"/>
<constructor-arg value="x-javascript"/>
<constructor-arg value="UTF-8"/>
</bean>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我还尝试了'ALL'构造函数arg,它应该支持*/*内容类型,但没有运气.见http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/http/MediaType.html
其他重要信息是我现在正在使用全XML配置.我刚刚将2.5应用程序升级到3.1.1.我在spring security PRE_AUTH过滤器中使用OAuth2RestTemplate,而不是在控制器中.所以我没有使用注释来映射其余的调用.我尝试过添加,<context:annotation-config/>但这并没有什么区别.
我只是从我的自定义AbstractPreAuthenticatedProcessingFilter调用我的OAuth服务bean.当服务bean尝试执行对用户数据的其余调用时,将引发异常,触发尝试检索令牌的OAuth2ClientContextFilter.这是我的OAuth2服务bean配置:
<bean id="reprintsOauthService" class="com.coral.user.ReprintsOauthService">
<property name="reprintsUserInfoUrl" value="https://www.demo.com/api/userinfo.ashx" />
<property name="reprintsRestTemplate">
<bean class="org.springframework.security.oauth2.client.OAuth2RestTemplate">
<constructor-arg ref="reprintsResource"/>
<property name="messageConverters">
<list>
<ref bean="jacksonConverter"/>
</list>
</property>
</bean>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?杰克逊为什么不映射回应?