![](/img/trans.png)
[英]How to use Spring Boot feign client for Oauth2 authentication?
[英]How to use a Swagger generated client (Feign)
我在很长一段时间内都在为同样的问题苦苦挣扎,我想分享一下我暂时让这个问题工作的方法。 默认情况下,swagger 将使用旧版 feign 客户端而不是新的 openfeign,因此您必须直接启用配置选项generateForOpenFeign
。 此外,如果您想使用 java8,为了避免生成默认接口(什么都不做),您已将配置选项defaultInterfaces
设置为 false。
这是我的swagger_config.json
样子:
{
"artifactId": "example-sdk",
"artifactVersion": "1.0.0",
"groupId": "com.example",
"apiPackage": "com.example.api",
"modelPackage": "com.example.model",
"configPackage": "com.example.configuration",
"generateForOpenFeign": true,
"java8": true,
"defaultInterfaces": false
}
源文件生成后,我必须更新pom.xml
中spring-cloud
和spring-boot-starter
的依赖,使de源代码可编译。
这是我更新的内容:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Greenwich.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
要使用生成的假客户端,我必须将@EnableFeignClients(basePackages = {"com.example.api"})
放在我的客户端应用程序的主类中。 我知道这不是最好的解决方案,如果有人有更好的主意,请指教。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.