Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: use of Maven properties configured in yaml

I'm trying to extract some properties from Maven and print them when my app starts. I'm using Spring Boot so the resource filtering is automatically done for me.

In my application.yml I have the following

  applicationName: "@project.artifactId@"
  buildVersion: "@project.version@"
  buildTimestamp: "@maven.build.timestamp@"

When I run this on IntelliJ, I get the desired result, my properties are populated and printed as expected (single quotes have the same result) Removing the quotes will give me an Exception from SnakeYaml regarding the use of the '@' character

When I run this on Cent-OS though, via a jar (java -jar blah..blah) the properties are not being resolved but are instead being treated as Strings and instead of the correct version numbers etc, what gets printed are the strings inside the quotes above.

Any ideas on how to fix this? Is it related to the way I run the jar?

I used this as an example

like image 258
mariosk89 Avatar asked Jun 06 '17 13:06

mariosk89


People also ask

Which is better to configure a Spring Boot project properties or YAML?

If you want to have multiple profiles in your Spring Boot project, by using the YAML file you just need to define one configuration file and put configuration data of specific profile into it, but if you use properties file you need to define individual file for each profile.

What is the use of properties in Maven?

Properties can be defined in a POM or in a Profile. The properties set in a POM or in a Maven Profile can be referenced just like any other property available throughout Maven. User-defined properties can be referenced in a POM, or they can be used to filter resources via the Maven Resource plugin.


1 Answers

@Value("${applicationName}")
private String applicationName;
like image 81
Myjay1516 Avatar answered Sep 19 '22 09:09

Myjay1516