title: Spring Inject/AutoWire a Groovy Class that is created at runtime
body: <p>I have a Spring Controlled Grovoy Script Executor class that executes a Groovy Script.</p>
  
  <p>Something like below</p>
  
  <pre><code>    final ClassLoader parent = getClass().getClassLoader();
      final GroovyClassLoader loader;
  
      loader = AccessController.doPrivileged(new PrivilegedAction&lt;GroovyClassLoader&gt;() {
          @Override
          public GroovyClassLoader run() {
              return new GroovyClassLoader(parent);
          }
      });
  
  
      this.groovyClass = loader.parseClass(" def returnSomthing() { return SpringControlledBean.action('Hello World') } ");
      final GroovyObject groovyObject = (GroovyObject) this.groovyClass.newInstance();
      final Object[] args = { };
      final Object result = groovyObject.invokeMethod("returnSomthing", args);
  </code></pre>
  
  <p>Is it possible to inject the <em>SpringControlledBean</em> in to the script ? via maybe a autowire, or get Spring to create the class understanding that the class will need to be recreated as the script will change?</p>
  
  <p>Autowire is possible if the class was part of the classpath and built with the java, but this script content is past at runtime, so not static for spring to know about.</p>