springfox-swagger-ui 3.0.0 配置,springfox-boot-starter 配置

springfox-swagger-ui 3.0之后就不会配置了

在3.0中,访问地址URL变了。

  • http://地址:端口/项目名/swagger-ui/index.html
  • http://地址:端口/项目名/swagger-ui/

springboot

maven项目引入

 <dependency>
     <groupId>io.springfoxgroupId>
     <artifactId>springfox-swagger2artifactId>
     <version>3.0.0version>
 dependency>
 <dependency>
     <groupId>io.springfoxgroupId>
     <artifactId>springfox-swagger-uiartifactId>
     <version>3.0.0version>
 dependency>
 <dependency>
     <groupId>io.springfoxgroupId>
     <artifactId>springfox-boot-starterartifactId>
     <version>3.0.0version>
 dependency>

gradle项目引入

    //https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
    implementation group: 'io.springfox', name: 'springfox-swagger2', version: '3.0.0'
    //https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
    implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
    //https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter
    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'

SwaggerConfig.java 配置


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
  @Bean
  public Docket createRestApi() {
    ApiInfo apiInfo =
        new ApiInfoBuilder()
            .title("日志管理系统API")
            .description("日志管理系统采用SpringBoot开发,API文档集成Swagger")
            .version("1.0")
            .contact(new Contact("余静", "https://github.com/yutils", "[email protected]"))
            .license("我的首页")
            .licenseUrl("https://weibo.com/32005200")
            .build();
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.hn.logmanage.Controller"))
        .paths(PathSelectors.any())
        .build();
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.
            addResourceHandler( "/swagger-ui/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
            .resourceChain(false);
  }

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController( "/swagger-ui/")
            .setViewName("forward:" +  "/swagger-ui/index.html");
  }
}

这是效果图

springfox-swagger-ui 3.0.0 配置,springfox-boot-starter 配置_第1张图片

这是官方说明文档
https://springfox.github.io/springfox/docs/snapshot/#changes-in-swagger-ui

如果帮助到了大家,点个赞或者来个关注。

你可能感兴趣的:(java,技术交流,swagger2,swagger,swagger3.0,boot-starter,swagger-ui)