4

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?

cosbor11
  • 14,709
  • 10
  • 54
  • 69
  • I don't see why Spring Boot would convert a String into a Double without reason. Are you sure that nothing in your code refer to a floating type ? – davidxxx Jun 11 '19 at 18:50
  • @davidxxx - Hi there. Thanks for commenting. I'm certain there is no reference of float or decimal or double or anything like that. – cosbor11 Jun 11 '19 at 19:13
  • Hi @cosbor11. Really strange (+1 for the corner case). To your seat, I would try to increase log level for Spring class and if not relevant information, try to debug step by step the Spring field injection. – davidxxx Jun 11 '19 at 19:30
  • @davidxxx - Good idea. I'll give it a try. – cosbor11 Jun 11 '19 at 19:52
  • You can also use [`@ConfigurationProperties`](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties) to explicitly define the properties data type. – Adhika Setya Pramudita Jun 12 '19 at 07:51

1 Answers1

1

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