Skip to content

Commit 61778ce

Browse files
committed
native-image-增加参数
1 parent 3970764 commit 61778ce

4 files changed

Lines changed: 241 additions & 0 deletions

File tree

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# Yunyu Server Native Image 本地构建与接口验证命令
2+
3+
## 1. 文档目标
4+
5+
本文档用于提供 `yunyu-server` 在本地进行 Native Image 构建、启动与接口验证时可直接执行的命令清单。
6+
7+
适用场景:
8+
9+
1. 本地修改了 `yunyu-native-image-support``yunyu-server`
10+
2. 想重新构建 Native 二进制
11+
3. 想快速验证 Native 环境下常用接口是否正常
12+
13+
## 2. 前置条件
14+
15+
执行前请先确认本机具备以下条件:
16+
17+
1. 已安装 GraalVM JDK 25
18+
2. 已安装 Maven
19+
3. 本地 MySQL 可访问
20+
4. 数据库 `yunyu` 已准备好,或允许系统自动初始化
21+
22+
当前本地验证默认使用:
23+
24+
1. MySQL 地址:`127.0.0.1:3306`
25+
2. 服务端口:`20000`
26+
3. Spring Profile:`native`
27+
28+
## 3. 本地构建命令
29+
30+
### 3.1 先安装 Native Support 工程
31+
32+
进入目录:
33+
34+
```bash
35+
cd /Users/wangpenglong/projects/full-stack-project/Yunyu/yunyu-native-image-support
36+
```
37+
38+
执行:
39+
40+
```bash
41+
mvn -q -Dmaven.repo.local=/Users/wangpenglong/usr/local/mavenRepository/aliRepository -DskipTests install
42+
```
43+
44+
作用:
45+
46+
1.`yunyu-native-image-support-core`
47+
2. `yunyu-native-image-support-lambda-override`
48+
3. `yunyu-native-image-support-starter`
49+
50+
安装到本地 Maven 仓库,供 `yunyu-server` Native 构建时引用。
51+
52+
### 3.2 再构建 `yunyu-server` Native 二进制
53+
54+
进入目录:
55+
56+
```bash
57+
cd /Users/wangpenglong/projects/full-stack-project/Yunyu/yunyu-server
58+
```
59+
60+
执行:
61+
62+
```bash
63+
mvn -q -Dmaven.repo.local=/Users/wangpenglong/usr/local/mavenRepository/aliRepository -DskipTests -Pnative package
64+
```
65+
66+
构建成功后产物位于:
67+
68+
```bash
69+
/Users/wangpenglong/projects/full-stack-project/Yunyu/yunyu-server/target/yunyu-server
70+
```
71+
72+
## 4. 本地启动命令
73+
74+
进入目录:
75+
76+
```bash
77+
cd /Users/wangpenglong/projects/full-stack-project/Yunyu/yunyu-server
78+
```
79+
80+
执行:
81+
82+
```bash
83+
./target/yunyu-server --spring.profiles.active=native
84+
```
85+
86+
启动成功后,默认访问地址:
87+
88+
```bash
89+
http://127.0.0.1:20000
90+
```
91+
92+
## 5. 常用验证命令
93+
94+
以下命令用于验证 Native Image 是否已经具备基本可用性。
95+
96+
### 5.1 健康检查
97+
98+
```bash
99+
curl -i http://127.0.0.1:20000/actuator/health
100+
```
101+
102+
预期:
103+
104+
1. 返回 `HTTP/1.1 200`
105+
2. 响应体包含 `status":"UP"`
106+
107+
### 5.2 登录接口
108+
109+
```bash
110+
curl -i -H 'Content-Type: application/json' \
111+
-d '{"account":"yunyu","password":"yunyu"}' \
112+
http://127.0.0.1:20000/api/auth/login
113+
```
114+
115+
预期:
116+
117+
1. 返回 `HTTP/1.1 200`
118+
2. `code=0`
119+
3. 返回 `accessToken`
120+
121+
### 5.3 文章分页列表接口
122+
123+
```bash
124+
curl -i 'http://127.0.0.1:20000/api/site/posts?pageNo=1&pageSize=10'
125+
```
126+
127+
预期:
128+
129+
1. 返回 `HTTP/1.1 200`
130+
2. `code=0`
131+
3. 返回分页数据 `list / total / totalPages`
132+
133+
说明:
134+
135+
这个接口可用于验证 Native 环境下分页查询与常规 MyBatis-Plus 查询链路是否正常。
136+
137+
### 5.4 `LambdaQueryWrapper` 查询接口
138+
139+
当前项目里,文章分页接口已经覆盖到了 `LambdaQueryWrapper` 查询链路,因此本地最常用的 Lambda 验证命令可以直接使用:
140+
141+
```bash
142+
curl -i 'http://127.0.0.1:20000/api/site/posts?pageNo=1&pageSize=10'
143+
```
144+
145+
如果这个接口正常返回,通常可以说明:
146+
147+
1. `LambdaUtils`
148+
2. `SerializedLambda`
149+
3. 自定义 GraalVM Feature
150+
4. MyBatis-Plus Lambda Native 兼容链路
151+
152+
已经基本工作正常。
153+
154+
### 5.5 Swagger 检查
155+
156+
Native 模式下当前默认关闭 `springdoc`,所以执行下面命令时:
157+
158+
```bash
159+
curl -i http://127.0.0.1:20000/swagger-ui.html
160+
```
161+
162+
预期是:
163+
164+
1. 不作为通过标准
165+
2. 即使返回非 200,也不代表 Native 构建失败
166+
167+
因为当前 `application-native.yml` 中本来就关闭了 Swagger 相关配置。
168+
169+
## 6. 推荐验证顺序
170+
171+
建议按以下顺序验证:
172+
173+
1. 先看启动日志,确认数据库初始化链路正常
174+
2. 再跑健康检查
175+
3. 再跑登录接口
176+
4. 最后跑文章分页接口
177+
178+
这是因为:
179+
180+
1. 健康检查能确认服务整体可用
181+
2. 登录接口能确认安全链路、数据库访问和 JSON 序列化可用
182+
3. 文章分页接口能确认 MyBatis-Plus 与 Lambda 查询链路可用
183+
184+
## 7. 常用排错命令
185+
186+
### 7.1 查看端口占用
187+
188+
```bash
189+
lsof -i :20000
190+
```
191+
192+
### 7.2 停止正在运行的 Native 进程
193+
194+
如果前台运行,直接 `Ctrl+C` 即可。
195+
196+
如果后台运行,可先查进程:
197+
198+
```bash
199+
ps -Ao pid,command | grep yunyu-server | grep -v grep
200+
```
201+
202+
再执行:
203+
204+
```bash
205+
kill <PID>
206+
```
207+
208+
### 7.3 重新构建前清理旧产物
209+
210+
进入 `yunyu-server` 目录后执行:
211+
212+
```bash
213+
mvn -q -Dmaven.repo.local=/Users/wangpenglong/usr/local/mavenRepository/aliRepository -DskipTests clean
214+
```
215+
216+
如果怀疑 `yunyu-native-image-support` 的本地安装产物不一致,也可以在 support 工程重新执行一次:
217+
218+
```bash
219+
mvn -q -Dmaven.repo.local=/Users/wangpenglong/usr/local/mavenRepository/aliRepository -DskipTests clean install
220+
```
221+
222+
## 8. 当前通过标准
223+
224+
当前本地 Native 验证通过,建议至少满足以下标准:
225+
226+
1. Native 二进制可成功构建
227+
2. Native 二进制可成功启动
228+
3. `GET /actuator/health` 返回 `200`
229+
4. `POST /api/auth/login` 返回 `200`
230+
5. `GET /api/site/posts?pageNo=1&pageSize=10` 返回 `200`
231+
232+
只要上述 5 项全部通过,就可以认为当前 Native Image 基本具备可部署性。

docs/后端/native-image/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
- [02-yunyu-native-image-support-开发落地设计.md](/Users/wangpenglong/projects/full-stack-project/Yunyu/docs/后端/native-image/02-yunyu-native-image-support-开发落地设计.md)
99
- [03-yunyu-server-native-image-构建与真机验证说明.md](/Users/wangpenglong/projects/full-stack-project/Yunyu/docs/后端/native-image/03-yunyu-server-native-image-构建与真机验证说明.md)
1010
- [04-yunyu-server-native-image-github-workflow-与-docker-部署方案.md](/Users/wangpenglong/projects/full-stack-project/Yunyu/docs/后端/native-image/04-yunyu-server-native-image-github-workflow-与-docker-部署方案.md)
11+
- [05-yunyu-server-native-image-本地构建与接口验证命令.md](/Users/wangpenglong/projects/full-stack-project/Yunyu/docs/后端/native-image/05-yunyu-server-native-image-本地构建与接口验证命令.md)
1112

1213
建议阅读顺序:
1314

1415
1. 先看 `01`,了解方案边界与结构设计
1516
2. 再看 `02`,了解模块职责与开发落地方式
1617
3. 再看 `03`,确认当前分支的实际构建方法、运行方式和验证结果
1718
4. 最后看 `04`,确认 GitHub Actions、Docker Native 部署与产物交付方案
19+
5. 本地调试时看 `05`,直接执行构建、启动和接口验证命令

docs/部署/05-Linux 升级最新镜像说明.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ docker compose logs -f yunyu-server
1919

2020
```bash
2121
docker compose pull yunyu-server && docker compose up -d yunyu-server
22+
23+
24+
docker compose pull yunyu-server-native && docker compose up -d yunyu-server-native
2225
```
2326

2427
## 二、当前场景说明

yunyu-server/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@
270270
<!-- Native 可执行文件名:默认与当前 Maven 项目的 artifactId 保持一致。 -->
271271
<imageName>${project.artifactId}</imageName>
272272
<buildArgs>
273+
<!-- 自定义 GraalVM Feature:补齐 Spring AOT 之外 MyBatis-Plus Native 仍缺失的元数据注册。 -->
274+
<buildArg>--features=com.ideaflow.yunyu.nativeimage.support.core.aot.YunyuNativeRuntimeFeature</buildArg>
275+
<!-- 传递启动类全限定名:让 Feature 在构建期能够推导默认扫描主包。 -->
276+
<buildArg>-Dyunyu.native.applicationClass=${yunyu.native.applicationClass}</buildArg>
273277
<!-- 禁止生成 fallback JVM 镜像:强制在构建期暴露真实 Native 兼容问题。 -->
274278
<buildArg>--no-fallback</buildArg>
275279
<!-- 固定文件编码为 UTF-8:避免 SQL、YAML 与中文资源在不同机器上出现编码差异。 -->

0 commit comments

Comments
 (0)