【问题标题】:Printing the jar version using in the spring boot application in logs在日志中使用 Spring Boot 应用程序打印 jar 版本
【发布时间】:2022-01-07 14:34:37
【问题描述】:

是否可以在日志中打印我们正在使用的 pom.xml 的 jar 版本。

例如,我在应用程序中使用 Jar aspose-email,我想在日志中打印我正在使用的版本。

如果可能,怎么做

【问题讨论】:

  • 为什么?你已经建立了一个特定的状态,它记录在你的 git repo 中你已经发布了你的应用程序,并希望为你的发布状态制作一个标签.. 就这样?

标签: spring spring-boot maven


【解决方案1】:

仅“打印它(任何“maven 属性”)以记录”:


  1. pom.xml:

    <properties>
      <foo>bar</foo>
      ...
    

    (这可以在整个 pom 中使用...)

  2. application.properties:

    my.domain.someKey=@foo@
    
  3. 一些 bean 将其引用为 @Value("${my.domain.someKey})String foo

  4. ...并记录它。 (LOGGER.info(foo))

参考:


“生产就绪”(网络曝光)方法:


假设这个spring-boot-starter(web,actuator)。

我们将此添加到我们的application.properties

# we need this (jmx is exposed by default):
management.endpoints.web.exposure.include=info
# ... and this (enables info.* properties):
management.info.env.enabled=true
# ...then can write here arbitrary values, starting with info.*
info.foo=foo
# ...or "filtered" from the pom, like e.g:
info.app.spring-boot.version=@project.parent.version@
# we can use here also any pom.properties like @my.property@
# for pessimistic enablement/opt out:
#management.endpoints.enabled-by-default=false 
#management.endpoint.info.enabled=true

然后在 http://localhost:8080/actuator/info 找到它们,例如:

{"foo":"foo","app":{"spring-boot":{"version":"2.6.2"}}}

参考:

【讨论】:

    猜你喜欢
    • 2020-01-19
    • 2019-08-24
    • 2019-04-03
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    相关资源
    最近更新 更多