zoukankan      html  css  js  c++  java
  • springboot-配置swagger

    1 新建springboot项目

    选择springboot

    这里根据自己选择适合的,

    继续next,这里省心的时候到了,选择自己需要的maven.

     选的比较多的是,

     然后next.命名自己项目名称。最后静静等待项目的启动。

    2 配置swagger

     1  新建包

     2

     

     将contrller 写一点简单的逻辑。

    2  maven 配置

    <!-- 引入Swagger3依赖 -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>

    3 config 配置

    package com.zhouqiang.demo.config;
    
    /**
     * @author :zhouqiang
     * @date :2021/8/4 18:05
     * @description:
     * @version: $
     */
    
    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.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    
    /**
     * Swagger配置类
     */
    @Configuration
    @EnableOpenApi
    public class SwaggerConfig {
    
    
        @Bean
        public Docket docket() {
            return new Docket(DocumentationType.OAS_30)
                    .apiInfo(apiInfo()).enable(true)
                    .select()
                    //apis: 添加swagger接口提取范围
                    .apis(RequestHandlerSelectors.basePackage("com.zhouqiang.demo"))
                    //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                    .paths(PathSelectors.any())
                    .build()
                    .groupName("123");
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("swagger项目接口文档")
                    .description("swagger项目描述")
                    .contact(new Contact("zhoqiang", "https://www.cnblogs.com/zq1003/", ""))
                    .version("1.0")
                    .build();
        }
    }

    4  加上swagger注解

    3 启动项目

     有些人启动会失败。

    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

     application.properties 是没有连接数据库。

     地址:本地+/swagger-ui/index.html

  • 相关阅读:
    实现Vector对象的序列化的例子
    BigDecimal
    java.io.Serializable引发的问题——什么是序列化?在什么情况下将类序列化?
    删除表中重复记录的方法
    使用PreparedStatement为不同的数据库编写可移植的数据库存取方法
    hsqldb介绍
    ant管理项目
    在jsp中点击按钮,在bean中把已经查出的数据,生成csv文件,然后在ie中自动打开
    用JAVA操作日期类型
    ORACLE默认用户的问题?
  • 原文地址:https://www.cnblogs.com/zq1003/p/15100381.html
Copyright © 2011-2022 走看看