springboot3.0.11-SNAPSHOT使用knife4j-openapi3所遇见的问题

本文档介绍了在SpringBoot 3.0.11-SNAPSHOT项目中使用Knife4j-OpenAPI3时遇到的两个主要问题及其解决方案:一是可以访问Swagger-UI但无法访问doc.html,二是doc.html找不到图标。解决方法包括在WebConfig中添加资源处理和忽略拦截器,以及手动添加favicon.ico图标并映射静态资源。
摘要由CSDN通过智能技术生成

1.本地工作环境

ide2021

jdk17

springboot3.0.11-SNAPSHOT

2.使用knife4j-openapi3的原因

在使用springboot3写完一个项目后,想快速生成一篇接口文档,供自己观看。在网上冲浪一段时间后,发现使用Swagger文档比较合适,通过少量的注解来完成一篇复杂的文档。说干就干,直接cope网上的资料写一个demo来用,发现项目无法正常启动。在翻阅了博客后,发现Swagger2暂时无法适配springboot3。后再其他博客中发现可以使用openapi兼容springboot3,同时,knife4j是对swagger的美化,所以使用knife4j-openapi3。

3.进行配置

对应的依赖如下:

<dependency>
     <groupId>com.github.xiaoymin</groupId>
     <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
     <version>4.1.0</version>
</dependency>

配置文件采用yml格式,所以在配置中对knife4j进行如下简单配置

# 在线文档配置
springdoc:
  swagger-ui:
    # 配置swagger-ui界面访问路径
    path: /swagger-ui.html
    # 包扫描路径
  packages-to-scan: com.pjx.sys.controller
  # 默认开启wend
  api-docs:
    enabled: true

上述的 packages-to-scan 也就是包扫描路径,是对控制层进行扫描,也就是你的controller层,只要扫描到外面那一层,不要深入到内部。路径可以直接复制。

此时还需对knife4j进行配置,才可以使用。

在自己的项目中创建SwaggerConfig类进行配置

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("标题")
                        //描叙
                        .description("我的API文档")
                        //版本
                        .version("v1")
                    
  • 10
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
There could be a few reasons why you are encountering this issue. Firstly, please ensure that you have the correct repository configuration in your project's pom.xml file. You can add the following repository configuration to your pom.xml file: ```xml <repositories> <repository> <id>nexus-aliyun</id> <url>https://your-nexus-aliyun-repository-url</url> </repository> </repositories> ``` Make sure to replace `https://your-nexus-aliyun-repository-url` with the actual URL of your Nexus Aliyun repository. If you already have the correct repository configuration, the next step is to check if the artifact `org.springframework.boot:spring-boot-starter-parent` with version `3.0.11-SNAPSHOT` is actually available in the Nexus Aliyun repository. You can do this by navigating to the Nexus Aliyun repository and searching for the artifact. If the artifact is not available in the Nexus Aliyun repository, you may need to check with the administrator or owner of the repository to ensure that the artifact is published and accessible. If you have confirmed that the artifact is available in the Nexus Aliyun repository, you may want to check if there are any network or connectivity issues preventing your project from accessing the repository. In such cases, you can try accessing the repository URL directly in a browser or using tools like `curl` to see if you can download the artifact manually. If none of these suggestions help, please provide more details about your project setup, such as your pom.xml file, repository configuration, and any error messages you are encountering.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值