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]
デフォルトの 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>
*/*
また、コンテンツ タイプをサポートするはずの 'ALL' コンストラクター引数も試しましたが、うまくいきませんでした。http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/http/MediaType.htmlを参照
その他の重要な情報は、現在すべての XML 構成を使用していることです。2.5 アプリを 3.1.1 にアップグレードしました。コントローラーではなく、春のセキュリティ 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>
何か不足していますか?Jackson が応答をマッピングしないのはなぜですか?