引入坐标:
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
application.yml:
# springdoc-openapi项目配置
springdoc:
swagger-ui:
path: /swagger-ui.html
tags-sorter: alpha
operations-sorter: alpha
api-docs:
path: /v3/api-docs
group-configs:
- group: 'default'
paths-to-match: '/**'
packages-to-scan: xxx.xxx.controller #改成你自己的controller包
# knife4j的增强配置,不需要增强可以不配
knife4j:
enable: true
setting:
language: zh_cn
一般来说以上的配置就行了。
但是,如果你配置了拦截器则需要放行,不然访问不了doc.html:
@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {
@Autowired
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 登陆和注册不拦截
registry.addInterceptor(loginInterceptor).excludePathPatterns("/login","/register","/static/**",
"/webjars/**","/doc.html","/v3/**" // knife4j相关放行
);
}
最后访问网址: