title: How to access spring.application.instance_id programmatically?
body: <p>I have the following content in my "applicationname.yml" file of my Spring Boot/Cloud application. How can i get the value of spring.application.instance_id in my java code ?  This "applicationname.yml" file is hosted in the 'Spring Cloud Config Server'.</p>
  
  <pre><code>eureka:
    password: password
    client:
      registryFetchIntervalSeconds: 5
      serviceUrl:
        defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:password@localhost:8761}/eureka/
    instance:
      preferIpAddress: true
      leaseRenewalIntervalInSeconds: 10
      metadataMap:
        instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
  </code></pre>
  
  <p>I have a java class where i am trying to access this variable's value using the @Value annotation and it gives me an error. Here is what i have to get and print the value in the java class</p>
  
  <pre><code>@Value("${eureka.instance.instanceId}")
  private String EinstanceId;
  
  @Value("${spring.application.instance_id}")
  private String SinstanceId;
  </code></pre>
  
  <p><strong><em>Error Message</em></strong>:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.citigroup.ccp.psg.error.PSGErrorFilter.instanceId; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'eureka.instance.instanceId' in string value "${eureka.instance.instanceId}"
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
      ... 49 more
  Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'eureka.instance.instanceId' in string value "${eureka.instance.instanceId}"
      at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
      at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
      at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)
      at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)
      at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:955)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
      ... 51 more
  </code></pre>