You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot自定义Banner在Windows 10环境下无法生效求助

Spring Boot自定义Banner在Windows 10环境无法显示

环境信息

  • Windows 10
  • IntelliJ 2022.2.1 Ultimate Edition
  • spring-boot-starter-parent 2.7.6

已执行操作

  • 在路径C:\Dev\intelliJUltimateDev\myapi\src\main\resources\下创建banner.txt文件
  • 在banner.txt中写入纯文本内容MY API
  • 启动Spring Boot应用

问题描述

同版本的IntelliJ和Spring Boot在MacBook上能正常显示自定义Banner,但Windows 10环境下启动应用时,控制台只显示默认的Spring Boot Banner,看不到自定义的MY API。

后来尝试添加banner.gif图片,并在配置文件中添加以下设置:

spring.output.ansi.enabled=always
spring.main.banner-mode=console
spring.banner.location=classpath:banner.txt
spring.banner.image.location=classpath:banner.gif
spring.banner.image.height=200
spring.banner.image.width=200

但问题依旧,控制台仍显示默认Banner:

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.6)

排查与解决方法

  1. 核对文件路径和名称

    • 确认banner.txt在src/main/resources根目录下,没被误放到子文件夹里
    • 文件名必须是banner.txt,别写成Banner.txt或banner.TXT——虽然Windows不区分大小写,但Spring Boot加载时严格匹配
  2. 检查资源是否被正确打包

    • 执行mvn clean package(Maven项目)或gradle build(Gradle项目),然后查看target/classes(Maven)或build/resources/main(Gradle)目录里有没有banner.txt
    • 如果没有,打开IntelliJ的File > Project Structure > Modules,确认src/main/resources被标记为Resources类型
  3. 清理缓存重启IDE

    • 清理IntelliJ缓存:File > Invalidate Caches...,勾选Clear file system cache and local history,点击Invalidate and Restart
    • 同时删除项目的target或build目录,重新构建项目
  4. 确认配置文件有效性

    • 检查修改的是不是正确的配置文件(比如application.properties),且该文件在src/main/resources下,没被其他环境配置文件覆盖
    • 如果用了多环境配置,确认当前激活的环境里没有覆盖spring.main.banner-mode这类设置
  5. 直接运行Jar包测试

    • 打包成Jar后,用命令行执行java -jar your-app.jar,看自定义Banner是否显示。如果Jar运行正常,说明是IntelliJ的运行配置问题
    • 检查IntelliJ的Run/Debug配置:确认Working directory是项目根目录,且没有额外启动参数覆盖Banner设置

内容的提问来源于stack exchange,提问作者pixel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 00:05:32