code: private BeanDefinitionRegistry getBeanDefinitionRegistry(ApplicationContext context) {
  		if (context instanceof BeanDefinitionRegistry) {
  			return (BeanDefinitionRegistry) context;
  		}
  		if (context instanceof AbstractApplicationContext) {
  			return (BeanDefinitionRegistry) ((AbstractApplicationContext) context)
  					.getBeanFactory();
  		}
  		throw new IllegalStateException("Could not locate BeanDefinitionRegistry");
  	}
docs: Get the bean definition registry.
  @param context the application context
  @return the BeanDefinitionRegistry if it can be determined