支持webflux的swagger版本
时间: 2023-09-29 09:06:48 浏览: 169
SpringBoot2+Swagger2
WebFlux集成Swagger2需要使用3.0.0以上的版本。你可以在pom.xml文件中添加以下依赖项来支持WebFlux的Swagger版本:
```xml
<properties>
<swagger.version>3.0.0</swagger.version>
</properties>
<!-- webflux集成swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${swagger.version}</version>
</dependency>
```
此外,你还需要在WebFlux的配置文件中添加Swagger路径的代码。你可以在WebfluxConfig类中添加以下代码:
```java
@Configuration
@EnableWebFlux
public class WebfluxConfig implements WebFluxConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}
}
```
最后,在应用主类上增加@EnableOpenApi注解,并删除之前版本的SwaggerConfig.java文件。启动项目后,你可以通过访问地址http://localhost:8200/swagger-ui/index.html来查看Swagger UI界面。注意,2.x版本中访问的地址为http://localhost:8200/swagger-ui.html。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [WebFlux整合MongoDB+WebFlux集成swagger2](https://blog.csdn.net/qq_43248715/article/details/127423499)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Webflux集成Swagger3](https://blog.csdn.net/weixin_46633487/article/details/119244118)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文