當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableBeanFactory.containsSingleton方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.ConfigurableBeanFactory.containsSingleton方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableBeanFactory.containsSingleton方法的具體用法?Java ConfigurableBeanFactory.containsSingleton怎麽用?Java ConfigurableBeanFactory.containsSingleton使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.config.ConfigurableBeanFactory的用法示例。


在下文中一共展示了ConfigurableBeanFactory.containsSingleton方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: intercept

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入方法依賴的package包/類
/**
 * Enhance a {@link Bean @Bean} method to check the supplied BeanFactory for the
 * existence of this bean object.
 * @throws Throwable as a catch-all for any exception that may be thrown when
 * invoking the super implementation of the proxied method i.e., the actual
 * {@code @Bean} method.
 */
@Override
public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs,
			MethodProxy cglibMethodProxy) throws Throwable {

	ConfigurableBeanFactory beanFactory = getBeanFactory(enhancedConfigInstance);
	String beanName = BeanAnnotationHelper.determineBeanNameFor(beanMethod);

	// Determine whether this bean is a scoped-proxy
	Scope scope = AnnotationUtils.findAnnotation(beanMethod, Scope.class);
	if (scope != null && scope.proxyMode() != ScopedProxyMode.NO) {
		String scopedBeanName = ScopedProxyCreator.getTargetBeanName(beanName);
		if (beanFactory.isCurrentlyInCreation(scopedBeanName)) {
			beanName = scopedBeanName;
		}
	}

	// To handle the case of an inter-bean method reference, we must explicitly check the
	// container for already cached instances.

	// First, check to see if the requested bean is a FactoryBean. If so, create a subclass
	// proxy that intercepts calls to getObject() and returns any cached bean instance.
	// This ensures that the semantics of calling a FactoryBean from within @Bean methods
	// is the same as that of referring to a FactoryBean within XML. See SPR-6602.
	if (factoryContainsBean(beanFactory, BeanFactory.FACTORY_BEAN_PREFIX + beanName) &&
			factoryContainsBean(beanFactory, beanName)) {
		Object factoryBean = beanFactory.getBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName);
		if (factoryBean instanceof ScopedProxyFactoryBean) {
			// Pass through - scoped proxy factory beans are a special case and should not
			// be further proxied
		}
		else {
			// It is a candidate FactoryBean - go ahead with enhancement
			return enhanceFactoryBean(factoryBean.getClass(), beanFactory, beanName);
		}
	}

	if (isCurrentlyInvokedFactoryMethod(beanMethod) && !beanFactory.containsSingleton(beanName)) {
		// The factory is calling the bean method in order to instantiate and register the bean
		// (i.e. via a getBean() call) -> invoke the super implementation of the method to actually
		// create the bean instance.
		if (BeanFactoryPostProcessor.class.isAssignableFrom(beanMethod.getReturnType())) {
			logger.warn(String.format("@Bean method %s.%s is non-static and returns an object " +
					"assignable to Spring's BeanFactoryPostProcessor interface. This will " +
					"result in a failure to process annotations such as @Autowired, " +
					"@Resource and @PostConstruct within the method's declaring " +
					"@Configuration class. Add the 'static' modifier to this method to avoid " +
					"these container lifecycle issues; see @Bean Javadoc for complete details",
					beanMethod.getDeclaringClass().getSimpleName(), beanMethod.getName()));
		}
		return cglibMethodProxy.invokeSuper(enhancedConfigInstance, beanMethodArgs);
	}
	else {
		// The user (i.e. not the factory) is requesting this bean through a
		// call to the bean method, direct or indirect. The bean may have already been
		// marked as 'in creation' in certain autowiring scenarios; if so, temporarily
		// set the in-creation status to false in order to avoid an exception.
		boolean alreadyInCreation = beanFactory.isCurrentlyInCreation(beanName);
		try {
			if (alreadyInCreation) {
				beanFactory.setCurrentlyInCreation(beanName, false);
			}
			return beanFactory.getBean(beanName);
		}
		finally {
			if (alreadyInCreation) {
				beanFactory.setCurrentlyInCreation(beanName, true);
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:78,代碼來源:ConfigurationClassEnhancer.java

示例2: isBeanEligible

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入方法依賴的package包/類
/**
 * Determine whether the specified bean  is eligible for inclusion in the
 * LiveBeansView JSON snapshot.
 * @param beanName the name of the bean
 * @param bd the corresponding bean definition
 * @param bf the containing bean factory
 * @return {@code true} if the bean is to be included; {@code false} otherwise
 */
protected boolean isBeanEligible(String beanName, BeanDefinition bd, ConfigurableBeanFactory bf) {
	return (bd.getRole() != BeanDefinition.ROLE_INFRASTRUCTURE &&
			(!bd.isLazyInit() || bf.containsSingleton(beanName)));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:LiveBeansView.java

示例3: isBeanEligible

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入方法依賴的package包/類
/**
 * Determine whether the specified bean is eligible for inclusion in the
 * LiveBeansView JSON snapshot.
 * @param beanName the name of the bean
 * @param bd the corresponding bean definition
 * @param bf the containing bean factory
 * @return {@code true} if the bean is to be included; {@code false} otherwise
 */
protected boolean isBeanEligible(String beanName, BeanDefinition bd, ConfigurableBeanFactory bf) {
	return (bd.getRole() != BeanDefinition.ROLE_INFRASTRUCTURE &&
			(!bd.isLazyInit() || bf.containsSingleton(beanName)));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:LiveBeansView.java


注:本文中的org.springframework.beans.factory.config.ConfigurableBeanFactory.containsSingleton方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。