springboot

Spring Boot 开发记录

Knife4j

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Maven坐标
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>

# application.yaml
# 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: com.xiaominfo.knife4j.demo.web
# knife4j的增强配置,不需要增强可以不配
knife4j:
enable: true
setting:
language: zh_cn

Slf4j

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# application.yaml
logging:
# 1. 日志级别配置
level:
# 全局日志级别
root: INFO
# 为特定包设置级别
top.daifudev.blog.v1.controller: DEBUG
# 为第三方库设置级别,减少干扰
org.springframework.web: INFO

# 2. 文件输出配置
file:
# 日志文件的路径和名称
name: logs/my-application.log
# 单个日志文件的最大大小 (触发滚动)
max-size: 10MB
# 保留的日志文件天数 (按日期滚动)
max-history: 30

# 3. 日志格式配置
pattern:
# 控制台输出格式
console: "%d{yyyy-MM-dd HH:mm:ss} - %magenta([%thread]) - %highlight(%-5level) - %cyan(%logger{36}) - %msg%n"
# 文件输出格式
file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"

redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
spring:
data:
redis:
host: 152.136.163.227 # Redis服务器地址[reference:6][reference:7]
port: 6379 # Redis服务器连接端口[reference:8][reference:9]
database: 0 # Redis数据库索引(默认为0)[reference:10]
password: # Redis服务器连接密码(默认为空)[reference:11]
timeout: 5000 # 连接超时时间(毫秒)[reference:12]
lettuce:
pool:
max-active: 100 # 最大并发连接数[reference:13]
max-idle: 50 # 最大空闲连接数[reference:14]
min-idle: 10 # 最小空闲连接数[reference:15]
max-wait: 2000 # 等待可用连接的最大时间(毫秒)[reference:16]

linux 部署jar包

1
2
3
4
5
6
7
nohup java -jar demo-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
│ │ │ │ │
│ │ │ │ └─ 后台运行
│ │ │ └─ 错误也写入日志
│ │ └─ 标准输出写入 app.log
│ └─ 运行 JAR 包
└─ 忽略挂起信号,终端关闭不退出