springboot 整合 swagger 在线文档生成工具

springboot 整合 swagger 在线文档生成工具

导入依赖 knife4j

<!-- 在线接口文档生成工具 -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>3.0.3</version>
</dependency>

配置数据源 application.properties

#数据源配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# 使用阿里的Druid连接池
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 填写你数据库的url、登录名、密码和数据库名
spring.datasource.url=xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
# 连接池的配置信息
# 初始化大小,最小,最大
spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.maxActive=20
# 配置获取连接等待超时的时间-1min
spring.datasource.druid.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
# 解决swagger报空指针
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

编写swagger配置类 SwaggerConfig.class

package com.sheep.emo.config;

/**
 * @author : sheep669
 * @description : swagger配置类
 * @created at 2022/7/9 23:08
 */

import io.swagger.annotations.Api;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.omg.CORBA.Request;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
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 {
    /**
     * 创建接口文档信息
     */
    public ApiInfo createApiInfo() {
        return new ApiInfoBuilder()
                .title("emo在线团购系统后台接口文档")
                .description("学习永无止境")
                .version("V1.0.0")
                .termsOfServiceUrl("https://blog.nowcoder.net/visya")
                .contact(new Contact("sheep669",
                        "https://blog.nowcoder.net/visya",
                        "sheep669@126.com"))
                .build();
    }

    @Bean
    public Docket createApi() {
        return new Docket(DocumentationType.SWAGGER_2).
                apiInfo(createApiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build();
    }

}

启动项目,访问文档地址

http://localhost:8080/doc.html

Over 感谢查阅

alt

全部评论

相关推荐

淬月星辉:专利是什么?至少描述一下吧,然后把什么计算机二级、普通话这种拉低格调的证书删掉,不然hr以为你没东西写
点赞 评论 收藏
分享
程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务