Spring Boot 横幅 - 自定义横幅不起作用

pix*_*xel 4 spring-boot

我已经阅读了几篇关于此的文章,并且我能够在运行相同版本的 IntelliJ 和 Spring Boot 的 Macbook 计算机上正常工作。

但是,在 Windows 10 上,自定义横幅不会显示。

  1. Windows 10
  2. IntelliJ 2022.2.1 旗舰版
  3. spring-boot-starter-parent 2.7.6

到目前为止我做了什么?

  1. 在 C:\Dev\intelliJUltimateDev\myapi\src\main\resources\banner.txt 中创建了banner.txt
  2. 将纯文本“ MY API”添加到banner.txt文件中
  3. 运行 Spring Boot 应用程序

当我运行 Spring Boot 应用程序时,我希望MY API自定义横幅显示在控制台中,但我看到的只是默认的 Springboot 横幅。在我的 MacBook 机器上,这就是我需要做的一切才能使其正常工作。

我还尝试添加 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
Run Code Online (Sandbox Code Playgroud)

,但这一切都没有改变任何事情。尽管如此,我看到的只是默认的 Springboot 横幅:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.6)
Run Code Online (Sandbox Code Playgroud)

小智 5

如果是Maven项目,检查pom.xml中是否启用了过滤:

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*.properties</include>
                    <include>*.xml</include>
                </includes>
            </resource>
        </resources>
Run Code Online (Sandbox Code Playgroud)

您可以像示例中的其他文件类型一样添加 *.txt:

                    <include>*.txt</include>
Run Code Online (Sandbox Code Playgroud)