title: How to pass constructor parameter while using spring auto wiring?
body: <p>Our Project is using spring DI/IoC, so i am using autowiring to inject beans. The program needs to pass parameters to an object during it's instantiation. And the parameters are know at run time (not at compile time).</p>
  
  <p>How to achive this while using autowiring. Sample code is as below.  </p>
  
  <p><strong>Interface</strong> - <strong>IMessage</strong> </p>
  
  <pre><code>package com.example.demo.services;
  
  public interface IMessage {
          String message(String name);
  }
  </code></pre>
  
  <p><strong>Implementations</strong> -<br>
  <strong>SayHelloService</strong></p>
  
  <pre><code>package com.example.demo.services;
  
  import org.springframework.stereotype.Service;
  
  @Service
  public class SayHelloService implements IMessage {
  
      String id;
  
      public SayHelloService(String id) {
          super();
          this.id = id;
      }
  
      @Override
      public String message(String name) {
          return "Hello Dear User - " + name + ". Greeter Id: " + id ;
      }
  }
  </code></pre>
  
  <p><strong>MasterService</strong>   </p>
  
  <pre><code>package com.example.demo.services;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.stereotype.Service;
  
  @Service
  public class MasterService implements IMessage  {
  
      String creationTime;
  
      MasterService() {
          System.out.println("ms... default constructor");
          creationTime = Long.toString(System.currentTimeMillis());
      }
  
      //classic java way of creating service
      IMessage sayHelloServiceClassicWay = new SayHelloService(creationTime);
  
      //how to achieve above using spring auto wiring. Below code does not exactly do same.
      @Autowired
      @Qualifier("sayHelloService")
      IMessage sayHelloServiceAutoWired;
  
      @Override
      public String message(String name) {
          return name.toString();
      }    
  }
  </code></pre>
  
  <p>Now  in the above program (in MasterService) how to replace</p>
  
  <blockquote>
    <p>IMessage sayHelloServiceClassicWay = new SayHelloService(creationTime);  </p>
  </blockquote>
  
  <p>with spring equivalent code.</p>