gateway网关聚合swagger2文档,由于gateway网关需要排除spring-web依赖,使用的是webFlux,故需要对swagger做一些配置
如下在对应的地方排除web依赖:
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
增加swagger依赖:这个依赖包括了ui和swagger
<!--knife4j版本的swagger-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
微服务通用模块中增加自定义注册swagger模块文档: 只有当配置了swagger扫描的服务会自动生成文档
package com.wm.blog_config.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Properties;
/**
* 文档配置
*/
@Configuration
@ConditionalOnProperty(name = "swagger.basepackage")
@EnableSwagger2
public class Knife4jConfig implements EnvironmentAware, WebMvcConfigurer {
private String basePackage;
private String c