carnellj / spmia-chapter7

Source code for chapter 7 of Spring Microservices in Action
46 stars 131 forks source link

OAuth2RestTemplate Config question #11

Closed baocaixue closed 4 years ago

baocaixue commented 4 years ago

Hi, John. I am reading your book. But it occurred a Error while config Oauth2RestTemplate. The Following is my Bean code:

@Bean
    public OAuth2RestTemplate oAuth2RestTemplate(OAuth2ProtectedResourceDetails details, @Qualifier("oauth2ClientContext") OAuth2ClientContext context) {
        return new OAuth2RestTemplate(details, context);
    }

The Following is consle stack trace info:

Description:

Parameter 0 of method oAuth2RestTemplate in com.isaac.licenses.LicenseApplication required a bean of type 'org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'oauth2RemoteResource' in 'OAuth2RestOperationsConfiguration.SingletonScopedConfiguration' not loaded because AnyNestedCondition 0 matched 2 did not; NestedCondition on OAuth2RestOperationsConfiguration.ClientCredentialsCondition.NoWebApplication @ConditionalOnWebApplication found 'session' scope and did not find reactive web application classes; NestedCondition on OAuth2RestOperationsConfiguration.ClientCredentialsCondition.ClientCredentialsConfigured @ConditionalOnProperty (security.oauth2.client.grant-type=client_credentials) did not find property 'grant-type'

Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails' in your configuration.

I am using SpringBoot 2.2.4.RELEASE and SpringCloud Hoxton.SR1 and spring-cloud-starter-oauth2

baocaixue commented 4 years ago

config security.oauth2.client.grant-type && security.oauth2.client.client-id could fix