1.引入依賴(lài)
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
2.配置文件
knife4j:
# 開(kāi)啟增強(qiáng)配置
enable: true
# 是否關(guān)閉調(diào)試頁(yè)面,如果為true,無(wú)法頁(yè)面調(diào)試接口,生產(chǎn)環(huán)境開(kāi)啟
production: false
# 開(kāi)啟Swagger的Basic認(rèn)證功能,默認(rèn)是false
basic:
enable: false
# Basic認(rèn)證用戶(hù)名
username: test
# Basic認(rèn)證密碼
password: 123
3.springsecurity放行相關(guān)接口
auth.requestMatchers("/auth/",
"/doc.html",
"/webjars/",
"/img.icons/",
"v3/api-docs",
"/v3/api-docs/swagger-config",
"/v3/api-docs/",
"/swagger-ui/index.html",
"swagger-resources/**",
"/v2/api-docs"
).permitAll()
4.頁(yè)面測(cè)試,訪(fǎng)問(wèn)http://127.0.0.1:8080/doc.html#/home

1700623906712.png