我在同一个问题上苦苦挣扎了很长一段时间,我想分享一下我暂时解决这个问题的方法。默认情况下,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>
要使用生成的 feign 客户端,我必须把
@EnableFeignClients(basePackages = {"com.example.api"}) 在我的客户端应用程序的主类中。
我知道这不是最好的解决方案,如果有人有更好的想法,请指教。