I have a OAuth2RestTemplate defined as below
@Configuration
@EnableOAuth2Client
public class TestOauth{
@Bean
public OAuth2RestTemplate restTemplate(){
OAuth2RestTemplate restTemplate= new OAuth2RestTemplate(buildResourceDetails());
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new
HttpComponentsClientHttpRequestFactory()));
return restTemplate;
}
@Bean
public ClientCredentialsResourceDetails buildResourceDetails(){
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("TestId");
resourceDetails.setClientSecret("TestSecret");
resourceDetails.setAccessTokenUri("TestURI");
return resourceDetails;
}
Now, in the calling class, I have it annotated as below and it works fine.
@Autowired
private OAuth2RestTemplate restTemplate;
I want to make this functionality generic and create the templates based of off clientId, secret and URI. How can I achieve this? Is creating multiple @bean methods (Separate method for each credentials) and based on the caller credentials, picking the corresponding bean from a map maybe the only way to achieve this?
I tried keeping only one @bean method and passing params to restTemplate method but I keep running into No qualifying bean of type [java.lang.String] found error
Please advise