I have trouble using swagger generated feign clients correctly. My service uses the password flow to generate tokens for the clients, the swagger generated feign client along with its configuration is as follows:
feign client configuration:
@Configuration
@EnableConfigurationProperties
public class ClientConfiguration {
public ClientConfiguration() {
}
@Bean
@ConditionalOnProperty({"app.security.oAuth2.client-id"})
public OAuth2FeignRequestInterceptor oAuth2RequestInterceptor() {
return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), this.oAuth2ResourceDetails());
}
@Bean
@ConditionalOnProperty({"app.security.oAuth2.client-id"})
@ConfigurationProperties("app.security.oAuth2")
public ResourceOwnerPasswordResourceDetails oAuth2ResourceDetails() {
ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
details.setAccessTokenUri("https://localhost:8000/as/token.oauth2");
return details;
}
}
feign client definition:
@FeignClient(name = "${app.name:app}", url = "${app.url:https://localhost}", configuration = {ClientConfiguration.class}
)
public interface FlowApiClient extends FlowApi {
}
my application.yml
app:
name: appName
url: http://localhost:8080
security:
oAuth2:
client-id: 123
client-secret: 456
username: test
password: test
Then I got following error messages:
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'app.security.oAuth2' is not valid
You cannot have ConfigurationProperties property name with capital letters (oAuth2) inside.
So instead of:
oAuth2
Try:
oauth2
Also, see this "issue" in the official Spring docs for more information: https://github.com/spring-projects/spring-boot/issues/9545