Register bean into application context.

@param <T>                the type parameter
@param applicationContext the application context
@param beanClazz          the bean clazz
@param beanId             the bean id
@return the type registered
431251
public static <T> T registerBeanIntoApplicationContext(final ConfigurableApplicationContext applicationContext,
                                                           final Class<T> beanClazz, final String beanId) {
        val beanFactory = applicationContext.getBeanFactory();
        val provider = beanFactory.createBean(beanClazz);
        beanFactory.initializeBean(provider, beanId);
        beanFactory.autowireBean(provider);
        beanFactory.registerSingleton(beanId, provider);
        return provider;
    }
1374685
private static void doLoadSpringGroovyResources(RuntimeSpringConfiguration config, GrailsApplication application,
                                                    GenericApplicationContext context) {
        loadExternalSpringConfig(config, application);
        if (context != null) {
            springGroovyResourcesBeanBuilder.registerBeans(context);
        }
    }
1296195
@Override
	public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
		// accepts the beans in the order of classpath, which allow me to override beans
		// easily
		if (containsBean(beanName)) {
			return;
		}
		// just continue normally
		super.registerBeanDefinition(beanName, beanDefinition);
	}
664808
@Nullable
    protected <T> BeanRegistration<T> getActiveBeanRegistration(BeanDefinition<T> beanDefinition, Qualifier qualifier) {
        if (beanDefinition == null) {
            return null;
        }
        return singletonObjects.get(new BeanKey(beanDefinition, qualifier));
    }
256954
@UsedByGeneratedCode
    public @Nonnull <T> T getBean(@Nullable BeanResolutionContext resolutionContext, @Nonnull Class<T> beanType) {
        ArgumentUtils.requireNonNull("beanType", beanType);
        return getBeanInternal(resolutionContext, beanType, null, true, true);
    }
745208
public static Map<String, Object> getBeansWithAnnotation(ApplicationContext appContext,
            Class<? extends Annotation> annotationType) {
        try {
            return appContext.getBeansWithAnnotation(annotationType);
        } catch (BeansException e) {
            return new HashMap<String, Object>();
        }
    }
306202
public synchronized ContainerRegistryBuilder createContainerBuilder(AppContextWrapper context) {
		containerLoaderAnnotation.startScan(context);

		ContainerFactory containerFactory = new ContainerFactory();
		ContainerWrapper cw = containerFactory.create(containerLoaderAnnotation.getConfigInfo());

		ContainerComponents configComponents = containerLoaderXML.loadAllContainerConfig(context);
		ContainerComponents aspectConfigComponents = containerLoaderXML.loadAllAspectConfig(context);

		return createContainerBuilder(context, cw, configComponents, aspectConfigComponents);
	}
47620
protected ViewDispatcher registerViewDispatcher(WebApplicationContext applicationContext) {
        // 并发下，重复注册虽然不会错误，但没有必要重复注册
        synchronized (applicationContext) {
            if (SpringUtils.getBean(applicationContext, viewDispatcherName) == null) {
                GenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
                        ViewDispatcherImpl.class);
                ((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory())
                        .registerBeanDefinition(viewDispatcherName, beanDefinition);
                if (logger.isDebugEnabled()) {
                    logger
                            .debug("registered bean definition:"
                                    + ViewDispatcherImpl.class.getName());
                }
            }
            return (ViewDispatcher) SpringUtils.getBean(applicationContext, viewDispatcherName);
        }
    }
1322890
@Override
    public void setApplicationContext(ApplicationContext appContext) throws BeansException {
        if (this.appContext != null) {
            throw new ApplicationContextException("Attempt to reinitialize application context.");
        }
        
        this.appContext = appContext;
    }
386713
public <T> void RegisterClazz( Clazz<T> clazz )
	{
		_ensureMap();

		if( clazzz.containsKey( clazz.getReflectedClass() ) )
			return;

		clazzz.put( clazz.getReflectedClass(), clazz );
	}
319188
public Contextual<?> getBean(Object beanKey)
    {
        if (passivationCapable)
        {
            return beanManager.getPassivationCapableBean((String) beanKey);
        }
        else
        {
            return (Contextual<?>) beanKey;
        }
    }
1021464
private Class<?> beanType(String name) {
		Class<?> type = context.getType(name);
		if (ClassUtils.isCglibProxyClass(type)) {
			return AopProxyUtils.ultimateTargetClass(context.getBean(name));
		}
		return type;
	}
417106
public AbstractEndpointBuilder<T> applicationContext(ApplicationContext applicationContext) {
        if (getEndpoint() instanceof ApplicationContextAware) {
            ((ApplicationContextAware) getEndpoint()).setApplicationContext(applicationContext);
        }

        if (getEndpoint() instanceof BeanFactoryAware) {
            ((BeanFactoryAware) getEndpoint()).setBeanFactory(applicationContext);
        }

        return this;
    }
94319
@SuppressWarnings("unchecked")
	public static void registerPattern(String id, String pattern, ParserContext parserContext) {
		if (!"".equals(id)) { // add to sitemap only if it has an id
			BeanDefinitionRegistry registry = parserContext.getRegistry();
			BeanDefinition sitemapBean;
			try {
				sitemapBean = registry.getBeanDefinition(BEAN_ID);
			} catch (NoSuchBeanDefinitionException e) {
				sitemapBean = BeanDefinitionBuilder.genericBeanDefinition(Sitemap.class)
					.addPropertyValue(BEAN_PROP_ENTRIES, new HashMap<String, String>())
					.getBeanDefinition();
				registry.registerBeanDefinition(BEAN_ID, sitemapBean);
			}
			((Map<String, String>) sitemapBean.getPropertyValues().getPropertyValue(BEAN_PROP_ENTRIES).getValue()).put(id, pattern);
		}
	}
983914
public void register(ApplicationContext applicationContext) {
    applicationContext
        .getBeansOfType(TransactionExceptionTranslator.class)
        .values()
        .forEach(transactionExceptionTranslatorRegistry::register);
  }
1146442
public void registerClass(Class<?> clazz) {
        registeredClasses.add(clazz);
        for (Field field : clazz.getFields()) {
            if (field.isAnnotationPresent(Opt.class)) {
                int mod = field.getModifiers();
                if (!Modifier.isPublic(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on non-public field: " + field); }
                if (Modifier.isFinal(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on final field: " + field); }
                if (Modifier.isAbstract(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on abstract field: " + field); }

                // Add an Apache Commons CLI Option for this field.
                Opt opt = field.getAnnotation(Opt.class);

                String name = getName(opt, field);
                if (!names.add(name)) {
                    throw new RuntimeException("Multiple options have the same name: --" + name);
                }

                String shortName = null;
                if (createShortNames) {
                    shortName = getAndAddUniqueShortName(name);
                }
                
                Option apacheOpt = new Option(shortName, name, opt.hasArg(), opt.description());                    
                apacheOpt.setRequired(opt.required());
                options.addOption(apacheOpt);

                optionFieldMap.put(apacheOpt, field);

                // Check that only boolean has hasArg() == false.
                if (!field.getType().equals(Boolean.TYPE) && !opt.hasArg()) {
                    throw new RuntimeException("Only booleans can not have arguments.");
                }
            }
        }
    }
1027957
public static <T> Map<String, T> getBeansOfType(ApplicationContext appContext, Class<T> clazz) {
        try {
            return appContext.getBeansOfType(clazz);
        } catch (BeansException e) {
            return new HashMap<String, T>();
        }
    }