Vamsi
Vamsi

Reputation: 35

Printing the jar version using in the spring boot application in logs

Is it possible to print the version of the jar we are using the pom.xml in logs.

For example, I'm using the Jar aspose-email in the application, I want to print the version whichever I'm using in logs.

If possible, how to do it

Upvotes: 2

Views: 2016

Answers (1)

xerx593
xerx593

Reputation: 13261

To only "print it (any "maven properties") to log":


  1. pom.xml:

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

    (this can be used throughout the pom...)

  2. application.properties:

    my.domain.someKey=@foo@
    
  3. Some bean referencing it as @Value("${my.domain.someKey})String foo.

  4. ...and logging it. (LOGGER.info(foo))

Refs:


A "production ready" (web exposure) approach:


Assuming this spring-boot-starter(web,actuator).

We add this to our 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:
[email protected]@
# 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

And find them at http://localhost:8080/actuator/info , like:

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

Refs:

Upvotes: 1

Related Questions