# print-server-address
**Repository Path**: netbuffer/print-server-address
## Basic Information
- **Project Name**: print-server-address
- **Description**: 实现基于SpringBoot开发的web应用,在工程启动后,打印出工程的web server端地址能力
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-06-16
- **Last Updated**: 2026-09-05
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 🖨️ print-server-address





> 🚀 一个轻量级的 Spring Boot 工具库 —— 应用启动完成后,自动在控制台打印项目的访问地址,再也不用翻日志猜端口了!
## ✨ 特性
- 🔌 **零配置接入** —— 引入依赖即生效,无需任何代码改动
- 🌐 **双地址输出** —— 同时打印 `localhost` 和局域网 IP 访问地址
- 🧩 **自动识别上下文** —— 自动读取 `server.port`、`server.servlet.context-path` 等配置
- 🎯 **只打印一次** —— 智能跳过子容器刷新事件,不会重复输出
- 🎨 **可定制装饰** —— 支持自定义打印内容的前后缀装饰符
## 📦 安装
```xml
cn.netbuffer
print-server-address
4.0.0
```
### 从 GitHub 仓库获取(Maven Central 之外的渠道)
每次发布 `v*` tag 时,CI 会自动把 jar 发布到 GitHub Release、GitHub Packages 以及 gh-pages 分支上的 Maven 仓库。
#### 方式一:gh-pages Maven 仓库(免登录,推荐) ✅
公网用户无需注册/令牌,只需在 `pom.xml` 中添加仓库后正常依赖即可:
```xml
netbuffer-github
https://raw.githubusercontent.com/netbuffer/print-server-address/gh-pages
cn.netbuffer
print-server-address
4.0.0
```
#### 方式二:GitHub Packages
> ⚠️ GitHub Packages 的限制:即使是公开包,拉取方也需要携带 GitHub 访问令牌(PAT,需 `read:packages` 权限)。
1. 在 `~/.m2/settings.xml` 中配置凭据:
```xml
github
你的GitHub用户名
ghp_xxxxxxxxxxxx
```
2. 在 `pom.xml` 中添加仓库与依赖:
```xml
github
https://maven.pkg.github.com/netbuffer/print-server-address
cn.netbuffer
print-server-address
4.0.0
```
#### 方式三:直接下载
前往 [GitHub Releases](https://github.com/netbuffer/print-server-address/releases) 页面手动下载 jar / sources / javadoc。
## 📋 环境兼容性
| Spring Boot | JDK | 是否支持 |
|:-----------:|:---:|:--------:|
| 2.x | 8+ | ✅ |
| 3.x | 17+ | ✅ |
| 4.x | 17+ | ✅ |
> 💡 单一 jar 全版本通用:同时提供 `spring.factories`(Boot 2.x)和 `AutoConfiguration.imports`(Boot 3.x/4.x)两种自动配置注册方式。
## 🚀 使用效果
启动应用后,控制台会输出:
```
▹▹▹▹▹▹▹▹ your app started,access [http://localhost:8080/, http://192.168.1.100:8080/] ◃◃◃◃◃◃◃◃
```
## 🔧 配置项
所有配置均为可选,通过 `application.yml` / `application.properties` 调整:
```yaml
print-server-address:
prefix: "🚀🚀🚀" # 打印内容前缀装饰,默认 ▹▹▹▹▹▹▹▹
suffix: "✅✅✅" # 打印内容后缀装饰,默认 ◃◃◃◃◃◃◃◃
ignore-parent-context: false # 为 true 时忽略父容器判断,子容器刷新时也会打印
```
| 配置项 | 说明 | 默认值 |
|--------|------|:------:|
| `prefix` | 输出前缀装饰符 | `▹▹▹▹▹▹▹▹` |
| `suffix` | 输出后缀装饰符 | `◃◃◃◃◃◃◃◃` |
| `ignore-parent-context` | 是否忽略父容器(Spring MVC 场景下根容器与子容器都会触发刷新事件) | `false` |
## ⚙️ 工作原理
1. 📡 监听 Spring 的 `ContextRefreshedEvent` 事件
2. 🔍 从 `Environment` 中读取 `server.port` 与 context-path 配置
3. 🏠 通过 `InetAddress.getLocalHost()` 获取本机局域网 IP
4. 🖨️ 组装并打印访问地址列表
## 📄 License
[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)