title: Spring boot environment variable are not reflecting properly
body: <p>I am working on spring boot application where I want to completely externalize my environment variables dynamically by config server.</p>
  
  <p>So below is the code I have written.</p>
  
  <p>Application.java</p>
  
  <pre><code>package com.util;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.web.support.SpringBootServletInitializer;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  
  @Configuration
  @SpringBootApplication
  @EnableAutoConfiguration
  @ComponentScan("com.myPackage, com.util")
  @PropertySource("classpath:application.properties")
  public class Application extends SpringBootServletInitializer {
  
      static final Logger logger = LoggerFactory.getLogger(Application.class);
      public static ApplicationContext ctx;
  
      public static void main(String[] args) throws Exception {
          logger.info("Application starting....");
          ctx = SpringApplication.run(Application.class, args);
          logger.info("Application started successfully....");
  
      }
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer
      propertySourcesPlaceholderConfigurer() {
          return new PropertySourcesPlaceholderConfigurer();
      }
  }
  </code></pre>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>server.port=${server.port}    
  ENDPOINT_SHAN=${name.mya}
  </code></pre>
  
  <p><strong>Config Server:</strong></p>
  
  <pre><code>APPLICATION_NAME=myapp
  server.port=8081
  name.mya=myName
  </code></pre>
  
  <p><strong>To Read Properties</strong></p>
  
  <pre><code>import org.springframework.core.env.Environment;
  import org.springframework.stereotype.Component;
  
  import com.apptium.Application;
  
  @Component("configurationProperties")
  public class ConfigurationProperties {
  
      private static Environment prop;
  
      public static String getConfigValue(String key)   {
          String value = null;
          if (prop == null) {
              prop = Application.ctx.getBean(Environment.class);
          }
          if (prop.getProperty(key) != null) {
              value = prop.getProperty(key).trim();
          }
          if (value == null &amp;&amp; System.getenv(key) !=null) {
              value = System.getenv(key).trim();
          }
          return value;
      }
  }
  </code></pre>
  
  <p>so, when I try to get the property <strong><code>ENDPOINT_SHAN</code></strong>, it is returning 
  <code>ENDPOINT_SHAN==${name.mya}</code> but it needs to return <code>ENDPOINT_SHAN==myName</code></p>
  
  <p>And also am wondering how the property for server.port is taken correctly.</p>
  
  <p>Anyways, I would like to know, how to get an actual property for <code>ENDPOINT_SHAN</code>.</p>