无法使用带有身份验证的伪装客户端生成的 swagger,无效 属性
Unable to use swagger generated with feign clients with authentication, invalid property
我无法正确使用 swagger 生成的假客户端。我的服务使用密码流为客户端生成令牌,swagger生成的feign客户端及其配置如下:
伪装客户端配置:
@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
然后我收到以下错误消息:
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'app.security.oAuth2' is not valid
您不能在 ConfigurationProperties 属性 名称中使用大写字母 (oAuth2)。
所以代替:
oAuth2
尝试:
oauth2
此外,请参阅官方 Spring 文档中的 "issue" 以获取更多信息:https://github.com/spring-projects/spring-boot/issues/9545
我无法正确使用 swagger 生成的假客户端。我的服务使用密码流为客户端生成令牌,swagger生成的feign客户端及其配置如下:
伪装客户端配置:
@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
然后我收到以下错误消息:
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'app.security.oAuth2' is not valid
您不能在 ConfigurationProperties 属性 名称中使用大写字母 (oAuth2)。
所以代替:
oAuth2
尝试:
oauth2
此外,请参阅官方 Spring 文档中的 "issue" 以获取更多信息:https://github.com/spring-projects/spring-boot/issues/9545