Spring boot 无法将属性clientid绑定到OAuth2Client属性$Registration
我正在开发一个spring启动应用程序,以便与另一个安全API通信。 为此,我实现了一个具有以下属性的OAuth2RestTemplate,但在运行应用程序时失败了Spring boot 无法将属性clientid绑定到OAuth2Client属性$Registration,spring-boot,spring-security-oauth2,Spring Boot,Spring Security Oauth2,我正在开发一个spring启动应用程序,以便与另一个安全API通信。 为此,我实现了一个具有以下属性的OAuth2RestTemplate,但在运行应用程序时失败了 @Configuration @EnableOAuth2Client class RestTemplateConfiguration { @Bean @ConfigurationProperties("oauth2") public OAuth2ProtectedResourceDetails oAuth2
@Configuration
@EnableOAuth2Client
class RestTemplateConfiguration {
@Bean
@ConfigurationProperties("oauth2")
public OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails() {
return new ClientCredentialsResourceDetails();
}
@Bean
public OAuth2RestTemplate oAuth2RestTemplate(
@Qualifier("oAuth2ProtectedResourceDetails") OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails) {
return new OAuth2RestTemplate(oAuth2ProtectedResourceDetails);
}
}
应用程序属性
spring:
security:
oauth2:
client:
registration:
clientId: xxxxxxxxxxxxxxxxxx
clientSecret: xxxxxxxxxxxxxxxxx
accessTokenUri: https://xxxxxx/oauth2/access_token
scope: openid profile xxxxxxxxxxx
authorizationGrantType: client_credentials
运行代码时得到的异常
Failed to bind properties under 'spring.security.oauth2.client.registration.clientid' to org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties$Registration:
我认为问题就在这里
security:
oauth2:
client:
registration:
mb:
client-name: mb
client-id: ui
client-secret: secret
authorization-grant-type: authorization_code
redirect-uri: http:localhost:8084/ui/login/oauth2/code/
scope: openId
client-authentication-method: basic
provider:
mb:
token-uri: http://localhost:8181/oauth/token
authorization-uri: http:localhost:8181/oauth/authorize
user-info-uri: http:localhost:8181/oauth/userinfo
user-name-attribute: name