突然 Springfox Swagger 3.0 无法与 spring webflux 一起使用 [英] Suddenly Springfox Swagger 3.0 is not working with spring webflux
问题描述
应用程序几天前正在使用 Springfox Swagger 3.0.突然停止工作.一周前创建的 Jar 文件仍在工作,但现在当我们尝试构建一个新的 Jar 文件时,即使没有任何代码/库更改,它也无法正常工作.我什至参考了以下网址,但仍然面临问题.
Application was working with Springfox Swagger 3.0 few days back. Suddenly it is stopped working. The Jar file which was created before a week is still working but now when we try to build a new Jar file, which is not working, even without any code/library changes. I have even referred the below URL but still facing issue.
404 错误与 swagger-ui 和 spring webflux
下面给出我的配置:
POM 文件:
<properties>
<java.version>1.8</java.version>
<springfox.version>3.0.0-SNAPSHOT</springfox.version>
<spring.version>2.3.1.RELEASE</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
配置文件:
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfiguration implements WebFluxConfigurer {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.description("My Reactive API")
.title("My Domain object API")
.version("1.0.0")
.build())
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("com.reactive.controller"))
.paths(PathSelectors.any())
.build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html**")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
当我尝试打开 Swagger 页面时出现 404 错误.
I am getting 404 error when I try to open the swagger page.
http://localhost:8080/swagger-ui.html
http://localhost:8080/swagger-ui.html
有人可以帮我解决这个问题吗?提前致谢.
Can someone help me with this. Thanks in advance.
推荐答案
最近实现发生了变化(见从早期的快照迁移 以获得关于此的简要更新).
The implementation has changed recently (see migrating from earlier snapshots for a brief update on this).
现在 UI 在 /swagger-ui
端点(不是 /swagger-ui.html
)下可用.
Now the UI is avaiable under /swagger-ui
endpoint (not /swagger-ui.html
).
您还应该删除 @EnableSwagger2WebFlux
注释和 addResourceHandlers()
方法,删除所有 springfox 依赖项并仅添加一个:
You should also drop the @EnableSwagger2WebFlux
annotation and addResourceHandlers()
method, remove all springfox dependencies and add just one:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.version}</version>
</dependency>
这篇关于突然 Springfox Swagger 3.0 无法与 spring webflux 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!