title: Spring bean instantiation by passing constructor args?
body: <p>I have below spring bean.</p>
  
  <pre><code>public class Employee2 {
  
    private int id;
    private String name;
    private double salary;
  
  
    public Employee2(int id, String name, double salary) {
      this.id = id;
      this.name = name;
      this.salary = salary;
    }
  
   // some logic to call database using above values
  
  }
  </code></pre>
  
  <p>Now i have below config in spring configuration file.</p>
  
  <pre><code>&lt;bean id="emp2" class="com.basic.Employee2"&gt;
              &lt;constructor-arg name="id" value="" /&gt;
              &lt;constructor-arg name="name" value="" /&gt;
              &lt;constructor-arg name="salary" value="" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now i cannot hard code the values in above config since they are dynamic.</p>
  
  <p>Now i am getting spring bean programmatically using below code. <strong>The bean scope is singelton</strong>.</p>
  
  <pre><code>Employee2 emp = (Employee2)applicationContext.getBean("emp2");
  </code></pre>
  
  <p>Now <strong>how can i pass the values to Employee2 constructor</strong>?</p>
  
  <p>Thanks!</p>