NosuchbeandefinitionException: без квалификационного боба типа 'org.springframework.security.oauth2.client.oauth2authoriJAVA

Программисты JAVA общаются здесь
Anonymous
NosuchbeandefinitionException: без квалификационного боба типа 'org.springframework.security.oauth2.client.oauth2authori

Сообщение Anonymous »

Я пытаюсь заставить клиента oauth2 отправиться в тип гранта клиентов и я следую новым функциям, выпущенным в 6.4, упомянутых здесь https://spring.io/blog/2024/10/28/restc ... ng-securit Доступно, как упомянуто здесь https://spring.io/blog/2024/10/28/restc ... 20Provides ,, In000%20Application.
Engune Encoundered P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P> P>.
Action:

Consider defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager' in your configuration.

....

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.510 s

package com.example.demo;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.endpoint.*;
import org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler;
import org.springframework.security.oauth2.client.web.client.OAuth2ClientHttpRequestInterceptor;
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
import org.springframework.web.client.RestClient;

@Configuration
public class RestClientConfig {

private final OAuth2AuthorizedClientManager authorizedClientManager;
private RestClient restClient;

public RestClientConfig(@Autowired OAuth2AuthorizedClientManager authorizedClientManager) {
this.authorizedClientManager = authorizedClientManager;
}

@PostConstruct
void initialize() {
OAuth2ClientHttpRequestInterceptor requestInterceptor =
new OAuth2ClientHttpRequestInterceptor(authorizedClientManager);
this.restClient =
RestClient.builder()
.messageConverters(
(messageConverters) -> {
messageConverters.clear();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new OAuth2AccessTokenResponseHttpMessageConverter());
})
.defaultStatusHandler(new OAuth2ErrorResponseErrorHandler())
// TODO: Customize the instance of RestClient as needed...
.requestInterceptor(requestInterceptor)
.build();
}

@Bean
public RestClient restClient() {
return this.restClient;
}

@Bean
public OAuth2AccessTokenResponseClient
authorizationCodeAccessTokenResponseClient() {
RestClientAuthorizationCodeTokenResponseClient accessTokenResponseClient =
new RestClientAuthorizationCodeTokenResponseClient();
accessTokenResponseClient.setRestClient(this.restClient);

return accessTokenResponseClient;
}

@Bean
public OAuth2AccessTokenResponseClient
refreshTokenAccessTokenResponseClient() {
RestClientRefreshTokenTokenResponseClient accessTokenResponseClient =
new RestClientRefreshTokenTokenResponseClient();
accessTokenResponseClient.setRestClient(this.restClient);

return accessTokenResponseClient;
}

@Bean
public OAuth2AccessTokenResponseClient
clientCredentialsAccessTokenResponseClient() {
RestClientClientCredentialsTokenResponseClient accessTokenResponseClient =
new RestClientClientCredentialsTokenResponseClient();
accessTokenResponseClient.setRestClient(this.restClient);

return accessTokenResponseClient;
}

@Bean
public OAuth2AccessTokenResponseClient
jwtBearerAccessTokenResponseClient() {
RestClientJwtBearerTokenResponseClient accessTokenResponseClient =
new RestClientJwtBearerTokenResponseClient();
accessTokenResponseClient.setRestClient(this.restClient);

return accessTokenResponseClient;
}

@Bean
public OAuth2AccessTokenResponseClient
tokenExchangeAccessTokenResponseClient() {
RestClientTokenExchangeTokenResponseClient accessTokenResponseClient =
new RestClientTokenExchangeTokenResponseClient();
accessTokenResponseClient.setRestClient(this.restClient);

return accessTokenResponseClient;
}
}


Подробнее здесь: https://stackoverflow.com/questions/792 ... ramework-s

Вернуться в «JAVA»