title: Register BeanFactory in SpringBoot
body: <p>First I'm not sure if it's a good idea to do all this.</p>
  
  <p>Goal is to create some interfaces with annotations to hide legacy position based string access out of a configuration database, without implementing each interface.</p>
  
  <p>Declarative configured Interface:</p>
  
  <pre class="lang-java prettyprint-override"><code>  public interface LegacyConfigItem extends ConfigDbAccess{
  
    @Subfield(length=3)
    String BWHG();
  
    @Subfield(start = 3, length=1)
    int BNKST();
  
    @Subfield(start = 4, length=1)
    int BEINH();
    :
    }
  </code></pre>
  
  <p>Base interface for runtime identification</p>
  
  <pre class="lang-java prettyprint-override"><code>  public interface ConfigDbAccess{
  
    }
  </code></pre>
  
  <p>Dummy implementation without functionality, may change.</p>
  
  <pre class="lang-java prettyprint-override"><code>  public class EmptyImpl {
  
    }
  </code></pre>
  
  <p>Beanfactory and MethodInvocation interceptor, to handle the unimplemented methods.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class InterfaceBeanFactory extends DefaultListableBeanFactory {
  
    protected static final int TEXT_MAX = 400;
  
    @Autowired
    private EntityRepo entityRepo;
  
     public &lt;T&gt; T getInstance(Class&lt;T&gt; legacyInterface, String key) {
      ProxyFactory factory = new ProxyFactory(new EmptyImpl());
      factory.setInterfaces(legacyInterface);
      factory.setExposeProxy(true);
      factory.addAdvice(new MethodInterceptor() {
  
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          KEY keyAnnotation = invocation.getThis().getClass().getAnnotation(Key.class);
          String key= keyAnnotation.key().toUpperCase();
          String ptart = invocation.getMethod().getDeclaringClass().getSimpleName();        
          Vpt result = entityRepo.getOne(new EntityId(ptart.toUpperCase(), schl.toUpperCase()));
          Subfield sub = invocation.getMethod().getAnnotation(Subfield.class);
          //TODO: Raise missing Subfield annotation
          int start = sub.start();
          int length = sub.length();
          if (start + length &gt; TEXT_MAX) {
            //TODO: Raise invalid Subfield config
          }
          String value = result.getTextField().substring(start,start+length);
          return value;
        }
      });
      return (T) factory.getProxy();
    }
  
    @Override
    protected Map&lt;String, Object&gt; findAutowireCandidates(String beanName, Class&lt;?&gt; requiredType, DependencyDescriptor descriptor) {
        Map&lt;String, Object&gt; map = super.findAutowireCandidates(beanName, requiredType, descriptor);
        if (ConfigDbAccess.class.isAssignableFrom(requiredType )) {
          :
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  public class JpaDemoApplication {
  
    @Autowired
    private ApplicationContext context;
      public static void main(String[] args) {
        SpringApplication app = new SpringApplication(JpaDemoApplication.class);
  //    app.setApplicationContextClass(InterfaceInjectionContext .class);
        app.run(args);
      }
  
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>public class InterfaceInjectionContext extends AnnotationConfigApplicationContext {
  
    public VptInjectionContext () {
      super (new InterfaceBeanFactory ());
    }
  }
  
  </code></pre>
  
  <p>So far I got all this stuff working, except when I try to set the applications Context class to my DefaultListableBeanFactory, I'm killing the Spring boot starter web. The application starts, injects the the Autowired fields with my intercepted  pseudo implementaition --- and ends.</p>
  
  <p>I think I'm doing something wrong with registering the DefaultListableBeanFactory, but I've no idea how to do it right.</p>