Prevent spring boot resolving properties to scientific notation

Viewed 676

I have a Spring Boot v2.1.0.RELEASE application with the following application.yml properties file:

example: 
  aws:
    account: 845216416540
  sqs:
    endpoint: https://sqs.us-west-2.amazonaws.com/${example.aws.account}

Then I use the property like this:

@Component public class Example {

   @Value("${example.aws.sqs.endpoint}")
   private String endpoint;

   public void test()
   {
      System.out.println(endpoint); 
      // prints -> https://sqs.us-west-2.amazonaws.com/8.4521641654E10
   }
}
  • No that is not my actual aws account (spare me the lecture)

Here is what I can't seem to figure out...

1) Why does spring by default interpolate the the value of the account as scientific notation?

2) How can I configure or prevent this from happening?

1 Answers

Spring is inferring the value to be a number. You can force the value to be treated as a string in YAML config by quoting it ie "845216416540"

This answer covers YAML convention in detail: https://stackoverflow.com/a/22235064/13172778

Related