title: Spring: how to dynamically create multiple beans from single template definition
body: <p>I have the following Spring bean for a remote web service defined in xml:</p>
  
  <pre><code>    &lt;bean id="authWSTemplate" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean" abstract="true"&gt;
         &lt;property name="serviceInterface" value="com.example.webservices.Authentication" /&gt;
         &lt;property name="wsdlDocumentUrl" value="${ws.root}/authentication?wsdl" /&gt;
         &lt;property name="namespaceUri" value="http://security.webservices.example.com/" /&gt;
         &lt;property name="serviceName" value="AuthenticationWebService" /&gt;
         &lt;property name="portName" value="AuthenticationPort" /&gt;
         &lt;property name="maintainSession" value="true" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>How do I obtain this bean template and create a concrete bean (i.e. supply the root property)? Can I then put the concrete bean into the Spring container?</p>
  
  <p>I need numerous concrete beans pointing to different systems, so I have different root values. For this example, say there are 2 systems with roots: <a href="http://domain1.com:8001/ws" rel="nofollow">http://domain1.com:8001/ws</a> and <a href="http://domain2.com:8002/ws" rel="nofollow">http://domain2.com:8002/ws</a>. </p>
  
  <p>Therefore I'd want 2 beans called "authWSdom1" and "authWSdom2". </p>
  
  <p>I'm expecting to do this programmatically in an application initialisation block, where I'd retrieve a list of all known system implementations (this info is only known at runtime), and create a bean for each impl, cache the bean name, then my application will retrieve the appropriate bean from the Spring container when required.</p>
  
  <p>Or, is there a better pattern for this? Perhaps by providing the root value in a constructor for the bean?</p>
  
  <p>I'm thinking I cannot have a single bean in Spring as I need to support concurrent access across multiple end points (i.e. multiple users hitting domain1 and domain2 at the same time).</p>