运行应用程序时,banner.txt 中定义的应用程序版本不会显示在控制台上。它是根据 docs of Spring Boot 定义的。
${application.version}
项目使用 spring-boot-starter-parent 作为父 pom(来自 start.spring.io 的基本项目设置)
最佳答案
Ok, the version gets printed if i build the project and run it via java -jar. But if i start the application within my IDE (IntelliJ IDEA) the version will not be printed.
根据 Customizing the Banner 上的 Spring Boot 文档,${application.version}
的值取自 jar list 。
The version number of your application as declared in MANIFEST.MF. For example Implementation-Version: 1.0 is printed as 1.0.
从 IDE 运行时,通常会针对 IDE 编译的类文件执行。 IDE 通常不会经历使用 list 构建整个 jar 的完整周期。因此,在运行时没有可用的 MANIFEST.MF 来替换 ${application.version}
的值,而您只剩下裸 token 。
这不是您的代码中的错误,您已经看到它在进行完整的 jar 构建时可以正常工作。如果在通过 IDE 运行时修复此问题真的很重要,那么您可以考虑设置一个自定义构建步骤,该步骤首先通过完整的 jar 构建和 list 生成。不过,这可能是矫枉过正。稍后可以通过对 jar 的真实发布版本进行测试,在 IDE 之外验证横幅。
关于java - 应用程序版本未显示在 Spring Boot banner.txt 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34519759/