温馨提示:本文翻译自stackoverflow.com,查看原文请点击:spring - Unable to use swagger generated with feign clients with authentication, invalid property
spring spring-cloud-feign spring-security-oauth2 swagger-codegen

spring - 无法使用带有身份验证的假客户端生成的摇摇欲坠,属性无效

发布于 2020-05-30 21:24:47

我在正确使用swagger生成的伪装客户端时遇到麻烦。我的服务使用密码流为客户端生成令牌,大张旗鼓生成的伪客户端及其配置如下:

伪装客户端配置:

@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;
}
}

伪装客户定义:

@FeignClient(name = "${app.name:app}", url = "${app.url:https://localhost}", configuration = {ClientConfiguration.class}
)
public interface FlowApiClient extends FlowApi {
}

我的application.yml

app:
  name: appName
  url: http://localhost:8080
  security:
    oAuth2:
      client-id: 123
      client-secret: 456
      username: test
      password: test

然后我收到以下错误消息:

引起原因:org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException:配置属性名称“ app.security.oAuth2”无效

查看更多

提问者
ascetic652
被浏览
9
Marco Behler 2020-03-16 03:59

您不能在ConfigurationProperties属性名称中使用大写字母(o A uth2)。

所以代替:

oAuth2

尝试:

oauth2

另外,请参阅官方Spring文档中的“问题”以获取更多信息:https : //github.com/spring-projects/spring-boot/issues/9545