// Create a new context which just serve as registry later
AbstractDelegatedExecutionApplicationContext context = new AbstractDelegatedExecutionApplicationContext() {
};
context.setBundleContext(bundleContext);
context.setPublishContextAsService(true);
context.refresh();
return context.getBeanFactory();
} else {
return ((ApplicationContext) bundleContext.getService(applicationContextRefs[0])).getAutowireCapableBeanFactory();
}