Spring Security OAuth2客户端报错@ConditionalOnProperty (security.oauth2.client.grant-type=client_credentials) did not find property ‘grant-type’

  • A+
所属分类:Spring Security

这几天在研究Spring Security OAuth2的客户端,但是各种报错,具体报错如下:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method oauth2RestTemplate in com.sso.ssoclient.Oauth2ClientConfig 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.

看这个报错信息,好像是说OAuth2ProtectedResourceDetails这个bean没有,然后我看了下代码,在@EnableOAuth2Client配置里有一个oauth2RestTemplate函数里用到了OAuth2ProtectedResourceDetails这个参数,我点到源码里发现这是一个interface,不是一个实现类,所以感觉是没有找到对应的实现类才报的错,难道需要我们自己来实现吗?感觉应该不用才对啊,后来在网上发现有的在配置文件里配置了OAuth2的相关配置,想到是不是因为没有配置引起的。

于是把下面的配置加上后工程就能正常启动了。

security:
  oauth2:
    resource:
      userInfoUri: http://localhost:8901/auth/user
    client:
      grant-type: client_credentials

所以报错信息里找不到的grant-type其实是在配置文件里配置的。。

ZPY

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: