title: Create Bean Proxy on the fly for Injection in Spring
body: <p>I have the following situation: 
  During the configuration/startup of Spring Boot, I am picking up a list of interfaces using reflections. These interfaces are replaced with a proxy implementation (using java.lang.reflect.Proxy, because I cannot use Spring's AOP). This is working.</p>
  
  <p>There is a super and the actual interface. So I have something like this:</p>
  
  <pre><code>public interface Stream{
  }
  
  public interface ExampleStream extends Stream{
      doAction();
  }
  </code></pre>
  
  <p>Now I want to use the interfaces in other beans unsing @Inject, e.g.</p>
  
  <pre><code>@Service
  public class MyService{
  
      @Inject
      private ExampleStream exampleStream;
  
      public void fooBar(){
          exampleStream.doAction();
      }
  }
  </code></pre>
  
  <p>And there is the method to initialize the proxy:</p>
  
  <pre><code>...
  StreamInvocationHandler invoHandler = ... // this implements InvocationHandler (the proxy)
  ClassLoader cl = ClassUtils.getDefaultClassLoader();
  Class&lt;? extends Stream&gt; stream = ... // fetch the class, which is ExampleStream.class
  Object impl = Proxy.newProxyInstance(cl, new Class[]{stream}, invoHandler);
  ExampleStream exampleStream = (ExampleStream)impl;
  // this is working
  exampleStream.doAction();
  </code></pre>
  
  <p>The mechanism should be equal to the spring data repositories (except of the <code>@Repository</code> annotation and so on...)</p>
  
  <p>But now, I don't know how to inject. Because of some SO answers, I tried to implement <code>ApplicationContextAware</code> as follows:</p>
  
  <pre><code>public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  ... // stuff from above
      AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
      beanFactory.autowireBean(impl);
      beanFactory.initializeBean(impl, "exampleBean");
  }
  </code></pre>
  
  <p>This did not work (field exampleStram in myservice has no qualifying bean...). I also tried another suggestion with a similar solution using <code>BeanDefinitionRegistryPostProcessor</code>, but this is only intended for bean definitions. </p>
  
  <p>Where and how can I inject those kinds of self created beans?</p>