title: Ask Spring for a Prototype instance of a Singleton Bean?
body: <p>I have a number of Grails Services that are singleton Spring beans, not prototypes.  </p>
  
  <p>Is there any way to retrieve a prototype instance (fully injected with any dependencies) of what is normally a singleton bean?</p>
  
  <p>I'd like this for testing purposes so that I can mess with the prototype instance (potentially changing it's metaClass to mock things out) without the risk of forgetting to clean up after any changes I make to the instance and having them leak into other tests.</p>
  
  <p>I've been playing around with this a little bit and haven't had any luck.  I've tried doing something like this:</p>
  
  <pre><code>def ctx = grailsApplication.mainContext
  
  ctx.registerPrototype("foo", MyService)
  </code></pre>
  
  <p>I'm then able to ask Spring for an instance of <code>MyService</code></p>
  
  <pre><code>def myServicePrototype = ctx.getBean("foo")
  </code></pre>
  
  <p>and it does give a new instance every time, but none of the instances have had their properties autowired up so they're all null.  I'm guessing theres some way to create a BeanDefinition and feed it to the BeanFactory with some of the autowire stuff that I must be missing turned on.  </p>
  
  <p>I'm hoping to come up with some generic solution that doesn't force me to explicitly annotate the target services in any way.</p>
  
  <p>Is there any way to directly ask the Spring applicationContext for a prototype version of what's normally a singleton?</p>