title: How to inject values from Java Class to Datasource Bean in spring
body: <p>This might sound like a novice question. I want to inject datasource properties (which I am getting at runtime) and inject it to the bean..</p>
  
  <p>I have a method in my javaclass...</p>
  
  <pre><code>public &lt;String,String&gt;map myMethod(Map&lt;String, String&gt; model) {
  
          Map mapA = new HashMap();
          mapA.put("username", "element 1");
          mapA.put("password", "element 2");
          mapA.put("host", "element 3");
  
          return map;
      }
  </code></pre>
  
  <p>I want to inject these values to my datasource bean in application-context.xml</p>
  
  <pre><code>   &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value=""/&gt; // inject values here
          &lt;property name="url" /&gt;
          &lt;property name="username" /&gt;
          &lt;property name="password" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I have seen numerous example on injecting values to beans using properties file but I could not figure out on how to inject a value from java class to the bean properties.</p>
  
  <p>Thanks</p>