title: how to instantiate a spring bean using a classloader?
body: <p>I have a specific requirement that i should be dynamically (at runtime) able to load and unload bean classes in my Spring IoC container.</p>
  
  <p>A bean needs to be</p>
  
  <ol>
  <li>created </li>
  <li>destroyed</li>
  <li>created again (from the same class, probable a new version of the same class)</li>
  </ol>
  
  <p>the problem i am facing is that since the class in step 1 is loaded in system classloader, it remains there even when i destroy the bean. So in the step 3 i get an object of the old class, not the new class.</p>
  
  <p>So the solution to my problem is to load the class in MyClassLoader instead of system classloader. </p>
  
  <p>So my steps become</p>
  
  <ol>
  <li>create the specific classloader</li>
  <li>create the bean using specific class loader</li>
  <li>set the bean reference to null and remove bean from AppContext</li>
  <li>set the classloader reference to null </li>
  </ol>
  
  <p>reload the bean using step 1 and 2</p>
  
  <p>My Question is how to implement the above approach in Spring IoC container?</p>
  
  <p>Thanks, </p>
  
  <p>Regards,</p>
  
  <p>Vimal</p>