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


Java BeanFactoryUtils類代碼示例

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


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

示例1: afterPropertiesSet

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
	String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.applicationContext, Object.class);
	for(String beanName : beanNames){
		Class<?> beanType = this.applicationContext.getType(beanName);
		if(beanType != null){
			final Class<?> userType = ClassUtils.getUserClass(beanType);
			ReflectionUtils.doWithMethods(userType, method -> {
				if(AnnotatedElementUtils.findMergedAnnotation(method, ReactiveSocket.class) != null) {
					ServiceMethodInfo info = new ServiceMethodInfo(method);
					logger.info("Registering remote endpoint at path {}, exchange {} for method {}", info.getMappingInfo().getPath(), info.getMappingInfo().getExchangeMode(), method);
					MethodHandler methodHandler = new MethodHandler(applicationContext.getBean(beanName), info);
					mappingHandlers.add(methodHandler);
				}
			});
		}
	}
	initDefaultConverters();
}
 
開發者ID:viniciusccarvalho,項目名稱:spring-cloud-sockets,代碼行數:20,代碼來源:DispatcherHandler.java

示例2: getType

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
@Override
public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
	String beanName = BeanFactoryUtils.transformedBeanName(name);

	Object bean = this.beans.get(beanName);
	if (bean == null) {
		throw new NoSuchBeanDefinitionException(beanName,
				"Defined beans are [" + StringUtils.collectionToCommaDelimitedString(this.beans.keySet()) + "]");
	}

	if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
		// If it's a FactoryBean, we want to look at what it creates, not the factory class.
		return ((FactoryBean<?>) bean).getObjectType();
	}
	return bean.getClass();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:StaticListableBeanFactory.java

示例3: getDataSourceBeanName

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Get the {@link DataSource} type bean name which corresponds to given data context id
 * @param registry Bean registry
 * @param beanFactory Bean factory
 * @param dataContextId Optional data context id
 * @return The DataSource bean name, or <code>null</code> if not found
 */
private static String getDataSourceBeanName(BeanDefinitionRegistry registry, BeanFactory beanFactory,
		String dataContextId) {
	// check unique DataSource if no data context id specified
	if (dataContextId == null && beanFactory instanceof ListableBeanFactory) {
		String[] dataSourceBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
				(ListableBeanFactory) beanFactory, DataSource.class, false, false);
		if (dataSourceBeanNames != null && dataSourceBeanNames.length == 1) {
			return dataSourceBeanNames[0];
		}
	}
	// check bean name using data context id
	String dsBeanName = BeanRegistryUtils.buildBeanName(dataContextId,
			EnableDataSource.DEFAULT_DATASOURCE_BEAN_NAME);
	if (registry.containsBeanDefinition(dsBeanName) && beanFactory.isTypeMatch(dsBeanName, DataSource.class)) {
		return dsBeanName;
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:26,代碼來源:JpaRegistrar.java

示例4: autodetectViewConfig

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ScriptTemplateView.java

示例5: customize

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	if (this.managementServerProperties == null) {
		this.managementServerProperties = BeanFactoryUtils
				.beanOfTypeIncludingAncestors(this.beanFactory,
						ManagementServerProperties.class);
		this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors(
				this.beanFactory, ServerProperties.class);
	}
	// Customize as per the parent context first (so e.g. the access logs go to
	// the same place)
	this.server.customize(container);
	// Then reset the error pages
	container.setErrorPages(Collections.<ErrorPage>emptySet());
	// and the context path
	container.setContextPath("");
	// and add the management-specific bits
	container.setPort(this.managementServerProperties.getPort());
	if (this.managementServerProperties.getSsl() != null) {
		container.setSsl(this.managementServerProperties.getSsl());
	}
	container.setServerHeader(this.server.getServerHeader());
	container.setAddress(this.managementServerProperties.getAddress());
	container.addErrorPages(new ErrorPage(this.server.getError().getPath()));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:26,代碼來源:EndpointWebMvcChildContextConfiguration.java

示例6: generateBeanName

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
protected String generateBeanName(String prefix, BeanDefinition def, ParserContext parserContext) {
	BeanDefinitionRegistry registry = parserContext.getRegistry();
	String name = prefix + BeanDefinitionReaderUtils.generateBeanName(def, registry);
	String generated = name;
	int counter = 0;

	while (registry.containsBeanDefinition(generated)) {
		generated = name + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
		if (parserContext.isNested()) {
			generated = generated.concat("#generated");
		}
		counter++;
	}

	return generated;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:17,代碼來源:AbstractReferenceDefinitionParser.java

示例7: getLifecycleBeans

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Retrieve all applicable Lifecycle beans: all singletons that have already been created,
 * as well as all SmartLifecycle beans (even if they are marked as lazy-init).
 * @return the Map of applicable beans, with bean names as keys and bean instances as values
 */
protected Map<String, Lifecycle> getLifecycleBeans() {
	Map<String, Lifecycle> beans = new LinkedHashMap<String, Lifecycle>();
	String[] beanNames = this.beanFactory.getBeanNamesForType(Lifecycle.class, false, false);
	for (String beanName : beanNames) {
		String beanNameToRegister = BeanFactoryUtils.transformedBeanName(beanName);
		boolean isFactoryBean = this.beanFactory.isFactoryBean(beanNameToRegister);
		String beanNameToCheck = (isFactoryBean ? BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
		if ((this.beanFactory.containsSingleton(beanNameToRegister) &&
				(!isFactoryBean || Lifecycle.class.isAssignableFrom(this.beanFactory.getType(beanNameToCheck)))) ||
				SmartLifecycle.class.isAssignableFrom(this.beanFactory.getType(beanNameToCheck))) {
			Lifecycle bean = this.beanFactory.getBean(beanNameToCheck, Lifecycle.class);
			if (bean != this) {
				beans.put(beanNameToRegister, bean);
			}
		}
	}
	return beans;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:DefaultLifecycleProcessor.java

示例8: qualifiedBeanOfType

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Obtain a bean of type {@code T} from the given {@code BeanFactory} declaring a qualifier
 * (e.g. {@code <qualifier>} or {@code @Qualifier}) matching the given qualifier).
 * @param bf the BeanFactory to get the target bean from
 * @param beanType the type of bean to retrieve
 * @param qualifier the qualifier for selecting between multiple bean matches
 * @return the matching bean of type {@code T} (never {@code null})
 * @throws NoSuchBeanDefinitionException if no matching bean of type {@code T} found
 */
private static <T> T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class<T> beanType, String qualifier) {
	Map<String, T> candidateBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, beanType);
	T matchingBean = null;
	for (String beanName : candidateBeans.keySet()) {
		if (isQualifierMatch(qualifier, beanName, bf)) {
			if (matchingBean != null) {
				throw new NoSuchBeanDefinitionException(qualifier, "No unique " + beanType.getSimpleName() +
						" bean found for qualifier '" + qualifier + "'");
			}
			matchingBean = candidateBeans.get(beanName);
		}
	}
	if (matchingBean != null) {
		return matchingBean;
	}
	else if (bf.containsBean(qualifier)) {
		// Fallback: target bean at least found by bean name - probably a manually registered singleton.
		return bf.getBean(qualifier, beanType);
	}
	else {
		throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() +
				" bean found for qualifier '" + qualifier + "' - neither qualifier match nor bean name match!");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:BeanFactoryAnnotationUtils.java

示例9: isAutowireCandidate

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Determine whether the specified bean definition qualifies as an autowire candidate,
 * to be injected into other beans which declare a dependency of matching type.
 * @param beanName the name of the bean definition to check
 * @param descriptor the descriptor of the dependency to resolve
 * @param resolver the AutowireCandidateResolver to use for the actual resolution algorithm
 * @return whether the bean should be considered as autowire candidate
 */
protected boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor, AutowireCandidateResolver resolver)
		throws NoSuchBeanDefinitionException {

	String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
	if (containsBeanDefinition(beanDefinitionName)) {
		return isAutowireCandidate(beanName, getMergedLocalBeanDefinition(beanDefinitionName), descriptor, resolver);
	}
	else if (containsSingleton(beanName)) {
		return isAutowireCandidate(beanName, new RootBeanDefinition(getType(beanName)), descriptor, resolver);
	}
	else if (getParentBeanFactory() instanceof DefaultListableBeanFactory) {
		// No bean definition found in this factory -> delegate to parent.
		return ((DefaultListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor, resolver);
	}
	else if (getParentBeanFactory() instanceof ConfigurableListableBeanFactory) {
		// If no DefaultListableBeanFactory, can't pass the resolver along.
		return ((ConfigurableListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor);
	}
	else {
		return true;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:DefaultListableBeanFactory.java

示例10: contextMatch

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
private FuzzyBoolean contextMatch(Class<?> targetType) {
	String advisedBeanName = getCurrentProxiedBeanName();
	if (advisedBeanName == null) {  // no proxy creation in progress
		// abstain; can't return YES, since that will make pointcut with negation fail
		return FuzzyBoolean.MAYBE;
	}
	if (BeanFactoryUtils.isGeneratedBeanName(advisedBeanName)) {
		return FuzzyBoolean.NO;
	}
	if (targetType != null) {
		boolean isFactory = FactoryBean.class.isAssignableFrom(targetType);
		return FuzzyBoolean.fromBoolean(
				matchesBeanName(isFactory ? BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName : advisedBeanName));
	}
	else {
		return FuzzyBoolean.fromBoolean(matchesBeanName(advisedBeanName) ||
				matchesBeanName(BeanFactory.FACTORY_BEAN_PREFIX + advisedBeanName));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:AspectJExpressionPointcut.java

示例11: findEntityManagerFactory

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Find an EntityManagerFactory with the given name in the given
 * Spring application context (represented as ListableBeanFactory).
 * <p>The specified unit name will be matched against the configured
 * persistence unit, provided that a discovered EntityManagerFactory
 * implements the {@link EntityManagerFactoryInfo} interface. If not,
 * the persistence unit name will be matched against the Spring bean name,
 * assuming that the EntityManagerFactory bean names follow that convention.
 * <p>If no unit name has been given, this method will search for a default
 * EntityManagerFactory through {@link ListableBeanFactory#getBean(Class)}.
 * @param beanFactory the ListableBeanFactory to search
 * @param unitName the name of the persistence unit (may be {@code null} or empty,
 * in which case a single bean of type EntityManagerFactory will be searched for)
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 * @see EntityManagerFactoryInfo#getPersistenceUnitName()
 */
public static EntityManagerFactory findEntityManagerFactory(
		ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException {

	Assert.notNull(beanFactory, "ListableBeanFactory must not be null");
	if (StringUtils.hasLength(unitName)) {
		// See whether we can find an EntityManagerFactory with matching persistence unit name.
		String[] candidateNames =
				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, EntityManagerFactory.class);
		for (String candidateName : candidateNames) {
			EntityManagerFactory emf = (EntityManagerFactory) beanFactory.getBean(candidateName);
			if (emf instanceof EntityManagerFactoryInfo) {
				if (unitName.equals(((EntityManagerFactoryInfo) emf).getPersistenceUnitName())) {
					return emf;
				}
			}
		}
		// No matching persistence unit found - simply take the EntityManagerFactory
		// with the persistence unit name as bean name (by convention).
		return beanFactory.getBean(unitName, EntityManagerFactory.class);
	}
	else {
		// Find unique EntityManagerFactory bean in the context, falling back to parent contexts.
		return beanFactory.getBean(EntityManagerFactory.class);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:EntityManagerFactoryUtils.java

示例12: findDefaultEntityManagerFactory

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Find a single default EntityManagerFactory in the Spring application context.
 * @return the default EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no single EntityManagerFactory in the context
 */
protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName)
		throws NoSuchBeanDefinitionException {

	String[] beanNames =
			BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, EntityManagerFactory.class);
	if (beanNames.length == 1) {
		String unitName = beanNames[0];
		EntityManagerFactory emf = (EntityManagerFactory) this.beanFactory.getBean(unitName);
		if (this.beanFactory instanceof ConfigurableBeanFactory) {
			((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
		}
		return emf;
	}
	else if (beanNames.length > 1) {
		throw new NoUniqueBeanDefinitionException(EntityManagerFactory.class, beanNames);
	}
	else {
		throw new NoSuchBeanDefinitionException(EntityManagerFactory.class);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:PersistenceAnnotationBeanPostProcessor.java

示例13: registerBeanDefinitions

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
	// Register JPA Datastore (transactional)
	if (beanFactory instanceof ListableBeanFactory) {
		String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
				(ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false);
		if (emfBeanNames == null || emfBeanNames.length == 0) {
			emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory,
					AbstractEntityManagerFactoryBean.class, true, false);
		}
		if (emfBeanNames != null && emfBeanNames.length == 1) {
			String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0];
			JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false,
					beanClassLoader);
		}
	}
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:18,代碼來源:JpaDatastoreAutoConfigurationRegistrar.java

示例14: HessianFilter

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
public HessianFilter(ServletContext context) {
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.findWebApplicationContext(context);
    String[] strarr = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(webApplicationContext, Object.class);
    for (String s : strarr) {
        Object target = webApplicationContext.getBean(s);
        HessianEndpoint hessianEndpointAnnotation = target.getClass().getAnnotation(HessianEndpoint.class);
        if (hessianEndpointAnnotation != null) {
            try {
                Class apiClz = null;
                Class[] interfacesClass = target.getClass().getInterfaces();
                if (interfacesClass != null && interfacesClass.length > 0) {
                    apiClz = interfacesClass[0];
                } else {
                    apiClz = target.getClass();
                }
                HessianSkeleton hessianSkeleton = new HessianSkeleton(target, apiClz);
                hessianSkeletonMap.put(HessianConstant.HESSIAN_PATH + hessianEndpointAnnotation.servicePattern(), hessianSkeleton);
            } catch (Exception e) {
                logger.error("registerProcessor error : " + e.getMessage(), e);
            }
        }

    }
}
 
開發者ID:paullyphang,項目名稱:nebo,代碼行數:25,代碼來源:HessianFilter.java

示例15: detectHandlers

import org.springframework.beans.factory.BeanFactoryUtils; //導入依賴的package包/類
/**
 * Register all handlers found in the current ApplicationContext.
 * <p>The actual URL determination for a handler is up to the concrete
 * {@link #determineUrlsForHandler(String)} implementation. A bean for
 * which no such URLs could be determined is simply not considered a handler.
 * @throws org.springframework.beans.BeansException if the handler couldn't be registered
 * @see #determineUrlsForHandler(String)
 */
protected void detectHandlers() throws BeansException {
	if (logger.isDebugEnabled()) {
		logger.debug("Looking for URL mappings in application context: " + getApplicationContext());
	}
	String[] beanNames = (this.detectHandlersInAncestorContexts ?
			BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getApplicationContext(), Object.class) :
			getApplicationContext().getBeanNamesForType(Object.class));

	// Take any bean name that we can determine URLs for.
	for (String beanName : beanNames) {
		String[] urls = determineUrlsForHandler(beanName);
		if (!ObjectUtils.isEmpty(urls)) {
			// URL paths found: Let's consider it a handler.
			registerHandler(urls, beanName);
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Rejected bean name '" + beanName + "': no URL paths identified");
			}
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:31,代碼來源:AbstractDetectingUrlHandlerMapping.java


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