title: Spring Autowiring a property within an autowired bean
body: <p>I'm a newbie to Spring. I'm facing a problem with Spring-Boot. I'm trying to autowire a field from an external config file into an autowired bean. I have the following classes</p>
  
  <p>App.java</p>
  
  <pre><code>public class App {
  
  @Autowired
  private Service service;
  
  public static void main(String[] args) {
  
      final SpringApplication app = new SpringApplication(App.class);
      //app.setShowBanner(false);
      app.run();
  }
  
  @PostConstruct
  public void foo() {
      System.out.println("Instantiated service name = " + service.serviceName);
  }
  }
  </code></pre>
  
  <p>AppConfig.java</p>
  
  <pre><code>@Configuration
  @ConfigurationProperties
  public class AppConfig {
  
  @Bean
  public Service service()    {
      return new Service1();
  }
  }
  </code></pre>
  
  <p>Service Interface</p>
  
  <pre><code>public interface Service {
      public String serviceName ="";
      public void getHistory(int days , Location location );
      public void getForecast(int days , Location location );
  }
  </code></pre>
  
  <p>Service1</p>
  
  <pre><code>@Configurable
  @ConfigurationProperties
  public class Service1 implements Service {
  
  @Autowired
  @Value("${serviceName}") 
  public String serviceName;
  //Available in external configuration file.
  //This autowiring is not reflected in the main method of the application.
  
  
  
  public void getHistory(int days , Location location)
  {
      //history code
  }
  
  public void getForecast(int days , Location location )
  {
      //forecast code
  }
  }
  </code></pre>
  
  <p>I'm unable to display the service name variable in the postconstruct method of the App class. Am I doing this right?</p>