swagger2升级到knife4j

适用版本:Spring Boot 2 + OpenAPI3 demo:knife4j-springdoc-openapi-demo

参照于官网:https://doc.xiaominfo.com/

1、下载依赖:(swgger依赖不用动)
<!-- 官网:https://doc.xiaominfo.com/  访问:http://{IP}:{端口}/doc.html -->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
            <version>4.4.0</version>
        </dependency>
2、配置yaml文件或nacos配置中心
knife4j:
  # 开启增强配置
  enable: true
  # 开启生产环境屏蔽
  production: false
  basic:
    # 是否开启认证
    enable: true
    # 用户名
    username: root
    # 密码
    password: root
3、使用OpenAPI3的规范注解(原swgger @API相关注解冲突不可用)

4、访问地址(http://{IP}:{端口}/doc.html

启动类代码:

public static void main(String[] args)
    {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(RuoYiSystemApplication.class, args);
        Environment env = applicationContext.getEnvironment();
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String port = env.getProperty("server.port");
//        String path = env.getProperty("server.servlet.context-path");
        System.out.println("(♥◠‿◠)ノ゙  系统模块启动成功   ლ(´ڡ`ლ)゙  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
        log.info("\n----------------------------------------------------------\n\t" +
//                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
//                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + "/doc.html\n" +
                "----------------------------------------------------------");
    }
5、效果图:

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值