springboot2.7整合knife4j4.3
时间: 2023-11-19 14:56:14 浏览: 388
springboot2.7整合knife4j4.3是指在Springboot 2.7版本中使用Knife4j 4.3进行API文档的生成和管理。具体步骤如下:
1.在pom.xml文件中添加Knife4j的依赖:
```
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
```
2.在application.yml文件中进行配置:
```
spring:
profiles:
active: dev
application:
name: demo-knife4j-openapi3
servlet:
multipart:
max-file-size: 10MB
max-request-size: 100MB
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
serialization:
fail-on-empty-beans: false
indent-output: true
write-dates-as-timestamps: false
write-null-map-values: false
write-empty-json-arrays: false
write-enums-using-to-string: true
http:
encoding:
charset: UTF-8
enabled: true
servlet:
session:
timeout: 30m
datasource:
url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 5
max-active: 20
test-on-borrow: true
validation-query: SELECT 1 FROM DUAL
filters: stat,wall,log4j
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
server:
port: 8080
tomcat:
uri-encoding: UTF-8
max-threads: 200
min-spare-threads: 10
max-http-header-size: 1048576
accesslog:
enabled: true
directory: logs
prefix: access_log
suffix: .log
rotate: true
pattern: common
knife4j:
title: demo-knife4j-openapi3
description: demo-knife4j-openapi3
version: 1.0.0
contact:
name: demo-knife4j-openapi3
url: http://localhost:8080/doc.html
email: demo-knife4j-openapi3@qq.com
license:
name: Apache License 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
terms-of-service-url: http://localhost:8080/doc.html
host: localhost:8080
packages: com.example.demo
```
3.在启动类上添加@EnableKnife4j注解:
```
@SpringBootApplication
@EnableKnife4j
public class DemoKnife4jOpenapi3Application {
public static void main(String[] args) {
SpringApplication.run(DemoKnife4jOpenapi3Application.class, args);
}
}
```
阅读全文