Swagger3 相比2配置变了

简介: Swagger3 相比2配置变了

1.引入依赖,版本3.0.0只引入一个即可

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>

2. 配置类SwaggerConfig

package org.fh.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
/**
 * 说明:Swagger 接口API生成
 * 作者:FH Admin
 * from fhadmin.org
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.fh.controller")) // 为当前包路径
                .paths(PathSelectors.any())
                .build();
    }
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("FH Admin Swagger3 RESTful API")   // 页面标题
        .version("3.0")               // 版本号
        .description("fhadmin.org")           // 描述
        .build();
  }
}

3.Swagger 拦截配置

package org.fh.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * 说明:Swagger 拦截配置
 * 作者:FH Admin
 * from fhadmin.org
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @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");
    }
}

4.访问 127.0.0.1:8081/swagger-ui/index.html

5.接口说明案例

处理类上加注解,比如
@Api("用户注册登录接口")
在方法上加注解,比如
@ApiOperation(value = "登录", notes="校验登录是否成功")
@ApiImplicitParam(name = "KEYDATA", value = "用户名密码混淆码组合", paramType = "query", required = true, dataType = "String")

 

目录
相关文章
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
312 1
|
前端开发 Java 程序员
如何在swagger2中配置header请求头等参数信息?(若不会,我便手把手教你)
如何在swagger2中配置header请求头等参数信息?(若不会,我便手把手教你)
3478 1
|
7月前
|
缓存 Java API
微服务——SpringBoot使用归纳——Spring Boot集成 Swagger2 展现在线接口文档——Swagger2 的配置
本文介绍了在Spring Boot中配置Swagger2的方法。通过创建一个配置类,添加`@Configuration`和`@EnableSwagger2`注解,使用Docket对象定义API文档的详细信息,包括标题、描述、版本和包路径等。配置完成后,访问`localhost:8080/swagger-ui.html`即可查看接口文档。文中还提示了可能因浏览器缓存导致的问题及解决方法。
751 0
微服务——SpringBoot使用归纳——Spring Boot集成 Swagger2 展现在线接口文档——Swagger2 的配置
|
Java
SpringBoot 配置 Swagger
SpringBoot 配置 Swagger
368 0
|
Java Maven 开发者
Springboot 整合 knife4j | Swagger文档最简单配置
Springboot 整合 knife4j | Swagger文档最简单配置
2073 0
Springboot 整合 knife4j | Swagger文档最简单配置
|
Java API Spring
Spring Boot中配置Swagger用于API文档
Spring Boot中配置Swagger用于API文档
|
JavaScript 应用服务中间件 nginx
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
nginx配置解决vue刷新404、swagger 页面访问(springboot+vue项目)
566 0
|
缓存 Java Spring
Springfox swagger2 自定义配置ApiInfo
Springfox swagger2 源码解析
888 0
|
Java 应用服务中间件 网络安全
Nginx配置静态页面+springboot应用+swagger+SSL的实现
Nginx配置静态页面+springboot应用+swagger+SSL的实现
524 0
|
安全 Java Spring
如何在调试开发阶段,在已经配置了springsecurity的情况下还能使用swagger或者knife4j
如何在调试开发阶段,在已经配置了springsecurity的情况下还能使用swagger或者knife4j
312 0