use spring-boot 2.x demo project
- https://shields.io/
- github source
- gitee source
- /actuator/health
- spring-boot-2.7.18-reference
- @ControllerAdvice
- Exceptions Process
- ResponseEntityExceptionHandler
- requestmapping
- mvc-sse
- hibernate_validator_reference
- https://docs.docker.com/compose/compose-file/compose-file-v3/#build
- https://hub.docker.com/_/openjdk
ns for nanoseconds
us for microseconds
ms for milliseconds
s for seconds
m for minutes
h for hours
d for days
mvn -Dmvn-arg=your param -DskipTests clean package -P test-Dparam,-Pyour profile
mvn help:systemDisplays a list of the platform details like system properties and environment variablesmvn help:helpDisplay help information on maven-help-plugin.Call mvn help:help -Ddetail=true -Dgoal= to display parameter details
- javamelody
- spring-restdocs
- templating-maven-plugin
- thymeleaf
- logback
推送代码到 master / main 分支或创建 v* 标签时,GitHub Actions 会自动完成编译、打包并发布镜像。
镜像同时发布在 GitHub Container Registry 和 Docker Hub,多架构支持 linux/amd64 与 linux/arm64:
# GitHub Container Registry(匿名可拉取)
docker pull ghcr.io/netbuffer/spring-boot-demo:1.0
# Docker Hub
docker pull javawiki/spring-boot-demo:1.0手动触发一次 Release:
git tag v1.0.1 && git push origin v1.0.1- 先通过maven打包到target目录下
- 执行构建指令:
cd target;docker build -f ../Dockerfile -t netbuffer/spring-boot-demo:1.0 ../(docker build -t netbuffer/spring-boot-demo:1.0 .)
- docker run --rm -it -p 9100:9100 netbuffer/spring-boot-demo:1.0
- docker-compose up (使用docker-compose启动服务)
需要注册DockerHub身份,再docker login登录对应的Registry
- docker images 找到镜像ID
- docker tag 镜像ID 你的DockerHub账户名/spring-boot-demo:1.0 打tag
- docker push 你的DockerHub账户名/spring-boot-demo:1.0 推送到远程
已发布到DockerHub,可以直接运行以下指令测试 https://hub.docker.com/r/javawiki/spring-boot-demo
- docker pull javawiki/spring-boot-demo:1.0 拉取远程镜像
- docker run -it --rm javawiki/spring-boot-demo:1.0 运行远程镜像
- spring-boot中统一修改http响应体内容的方法
- spring-boot中异常的处理
- 关于spring-boot中logback日志配置引用spring环境变量的使用方式
- spring-boot生成打包信息
- spring-boot生成git版本库信息
- Spring Boot动态注册/删除http资源路径的方法
- 获取SpringBoot工程运行时的操作系统进程ID方法
- SpringBoot使用基于json格式的配置方法
- 怎么查看SpringBoot工程中每个过滤器的执行顺序
- Spring中出现NoUniqueBeanDefinitionException的解决方法
.github/workflows/build.yml 定义 4 个 Job:
| Job | 触发条件 | 职责 |
|---|---|---|
build |
push (master/main/v*) + PR | Dragonwell JDK 8 编译,上传 target/spring-boot-demo.jar 为 artifact(保留 30 天) |
release |
tag v* |
由 artifact 创建 GitHub Release,自动生成 release notes |
docker-ghcr |
tag v* |
多架构(amd64 + arm64)构建并推送到 ghcr.io/netbuffer/spring-boot-demo,打 :<VERSION> 与 :latest |
docker-hub |
tag v* |
多架构构建并推送到 javawiki/spring-boot-demo,打 :<VERSION> 与 :latest |
在仓库 Settings → Secrets and variables → Actions 中配置:
| Secret | 必填 | 说明 |
|---|---|---|
DOCKERHUB_USERNAME |
✓ | Docker Hub 用户名(当前为 javawiki) |
DOCKERHUB_TOKEN |
✓ | Docker Hub Access Token,从 hub.docker.com/settings/security 生成,需 Read & Write 权限 |
GITHUB_TOKEN |
- | GitHub Actions 自动注入,无需手动创建,权限由 workflow 的 permissions: packages: write 决定 |
第一次自动推送后,包默认是 private。前往仓库 Settings → Packages → spring-boot-demo → Package settings → Danger Zone → Change visibility 改为 Public。
可以用 act(本机需 Docker)模拟运行 build Job:
act push -j build注意:act 无法完整模拟 docker-ghcr / docker-hub Job 的镜像推送。