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


Java ConfigurableBeanFactory類代碼示例

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


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

示例1: copyConfigurationFrom

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Override
public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
	Assert.notNull(otherFactory, "BeanFactory must not be null");
	setBeanClassLoader(otherFactory.getBeanClassLoader());
	setCacheBeanMetadata(otherFactory.isCacheBeanMetadata());
	setBeanExpressionResolver(otherFactory.getBeanExpressionResolver());
	if (otherFactory instanceof AbstractBeanFactory) {
		AbstractBeanFactory otherAbstractFactory = (AbstractBeanFactory) otherFactory;
		this.customEditors.putAll(otherAbstractFactory.customEditors);
		this.propertyEditorRegistrars.addAll(otherAbstractFactory.propertyEditorRegistrars);
		this.beanPostProcessors.addAll(otherAbstractFactory.beanPostProcessors);
		this.hasInstantiationAwareBeanPostProcessors = this.hasInstantiationAwareBeanPostProcessors ||
				otherAbstractFactory.hasInstantiationAwareBeanPostProcessors;
		this.hasDestructionAwareBeanPostProcessors = this.hasDestructionAwareBeanPostProcessors ||
				otherAbstractFactory.hasDestructionAwareBeanPostProcessors;
		this.scopes.putAll(otherAbstractFactory.scopes);
		this.securityContextProvider = otherAbstractFactory.securityContextProvider;
	}
	else {
		setTypeConverter(otherFactory.getTypeConverter());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:AbstractBeanFactory.java

示例2: detectAnnotatedFactoryMethods

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Detect relationships in annotated {@link Bean @Bean} Factory methods.
 * 
 * @return Relationships detected from factory methods.
 */
protected Set<Relationship> detectAnnotatedFactoryMethods() {
    Set<Relationship> result = new HashSet<>();
    /* retrieve all beans declared in the application context */
    String[] annotateBeans = applicationContext.getBeanDefinitionNames();
    ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
    for (String beanName : annotateBeans) {
        /* ... and get the bean definition of each declared beans */
        Optional<MethodMetadata> metadata = getMethodMetadata(factory.getMergedBeanDefinition(beanName));
        if (metadata.isPresent()) {
            Set<Relationship> rel = detectMethodMetadata(metadata.get());
            result.addAll(rel);
        }
    }
    return result;
}
 
開發者ID:cereebro,項目名稱:cereebro,代碼行數:21,代碼來源:AnnotationRelationshipDetector.java

示例3: auditorAware

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AuditorAware<Username> auditorAware() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    log.debug("current authentication:" + authentication);

    if (authentication == null || !authentication.isAuthenticated()) {
        return () -> Optional.<Username>empty();
    }

    return () -> Optional.of(
        Username.builder()
            .username(((UserDetails) authentication.getPrincipal()).getUsername())
            .build()
    );

}
 
開發者ID:hantsy,項目名稱:spring-microservice-sample,代碼行數:20,代碼來源:DataJpaConfig.java

示例4: HandlerMethodService

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
public HandlerMethodService(ConversionService conversionService,
		List<HandlerMethodArgumentResolver> customArgumentResolvers,
		ObjectMapper objectMapper, ApplicationContext applicationContext) {
	this.conversionService = conversionService;
	this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();

	this.argumentResolvers = new HandlerMethodArgumentResolverComposite();

	ConfigurableBeanFactory beanFactory = ClassUtils.isAssignableValue(
			ConfigurableApplicationContext.class, applicationContext)
					? ((ConfigurableApplicationContext) applicationContext)
							.getBeanFactory()
					: null;

	this.argumentResolvers.addResolver(
			new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	this.argumentResolvers.addResolver(new HeadersMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampMessageMethodArgumentResolver());
	this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampSessionIdMethodArgumentResolver());
	this.argumentResolvers.addResolvers(customArgumentResolvers);

	this.objectMapper = objectMapper;
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:25,代碼來源:HandlerMethodService.java

示例5: setBeanFactory

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Override
public void setBeanFactory(BeanFactory beanFactory) {
	if (!(beanFactory instanceof ConfigurableBeanFactory)) {
		throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with a BeanFactory "
				+ "which does not implement ConfigurableBeanFactory: " + beanFactory.getClass());
	}
	this.beanFactory = (ConfigurableBeanFactory) beanFactory;

	// Required so that references (up container hierarchies) are correctly resolved.
	this.scriptBeanFactory.setParentBeanFactory(this.beanFactory);

	// Required so that all BeanPostProcessors, Scopes, etc become available.
	this.scriptBeanFactory.copyConfigurationFrom(this.beanFactory);

	// Filter out BeanPostProcessors that are part of the AOP infrastructure,
	// since those are only meant to apply to beans defined in the original factory.
	for (Iterator<BeanPostProcessor> it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
		if (it.next() instanceof AopInfrastructureBean) {
			it.remove();
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:ScriptFactoryPostProcessor.java

示例6: invokeAwareMethods

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
 * {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
 */
private void invokeAwareMethods(Object importStrategyBean) {
	if (importStrategyBean instanceof Aware) {
		if (importStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) importStrategyBean).setEnvironment(this.environment);
		}
		if (importStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader);
		}
		if (importStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
					this.resourceLoader.getClassLoader());
			((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader);
		}
		if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
			((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:ConfigurationClassParser.java

示例7: enhanceFactoryBean

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory
 * instead of creating a new instance. These proxies are created only when calling a FactoryBean from
 * within a Bean method, allowing for proper scoping semantics even when working against the FactoryBean
 * instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
 * it will not be proxied. This too is aligned with the way XML configuration works.
 */
private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory,
		final String beanName) throws InstantiationException, IllegalAccessException {

	Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(fbClass);
	enhancer.setUseFactory(false);
	enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
	enhancer.setCallback(new MethodInterceptor() {
		@Override
		public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
			if (method.getName().equals("getObject") && args.length == 0) {
				return beanFactory.getBean(beanName);
			}
			return proxy.invokeSuper(obj, args);
		}
	});
	return enhancer.create();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ConfigurationClassEnhancer.java

示例8: getResourceToInject

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Override
protected Object getResourceToInject(Object target, String requestingBeanName) {
	if (StringUtils.hasLength(this.beanName)) {
		if (beanFactory != null && beanFactory.containsBean(this.beanName)) {
			// Local match found for explicitly specified local bean name.
			Object bean = beanFactory.getBean(this.beanName, this.lookupType);
			if (beanFactory instanceof ConfigurableBeanFactory) {
				((ConfigurableBeanFactory) beanFactory).registerDependentBean(this.beanName, requestingBeanName);
			}
			return bean;
		}
		else if (this.isDefaultName && !StringUtils.hasLength(this.mappedName)) {
			throw new NoSuchBeanDefinitionException(this.beanName,
					"Cannot resolve 'beanName' in local BeanFactory. Consider specifying a general 'name' value instead.");
		}
	}
	// JNDI name lookup - may still go to a local BeanFactory.
	return getResource(this, requestingBeanName);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:CommonAnnotationBeanPostProcessor.java

示例9: isFactoryBean

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Override
public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException {
	String beanName = transformedBeanName(name);

	Object beanInstance = getSingleton(beanName, false);
	if (beanInstance != null) {
		return (beanInstance instanceof FactoryBean);
	}
	else if (containsSingleton(beanName)) {
		// null instance registered
		return false;
	}

	// No singleton instance found -> check bean definition.
	if (!containsBeanDefinition(beanName) && getParentBeanFactory() instanceof ConfigurableBeanFactory) {
		// No bean definition found in this factory -> delegate to parent.
		return ((ConfigurableBeanFactory) getParentBeanFactory()).isFactoryBean(name);
	}

	return isFactoryBean(beanName, getMergedLocalBeanDefinition(beanName));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:AbstractBeanFactory.java

示例10: destroyPrototypeInstance

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Subclasses should call this method to destroy an obsolete prototype instance.
 * @param target the bean instance to destroy
 */
protected void destroyPrototypeInstance(Object target) {
	if (this.logger.isDebugEnabled()) {
		this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
	}
	if (getBeanFactory() instanceof ConfigurableBeanFactory) {
		((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
	}
	else if (target instanceof DisposableBean) {
		try {
			((DisposableBean) target).destroy();
		}
		catch (Throwable ex) {
			logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:AbstractPrototypeBasedTargetSource.java

示例11: buildInternalBeanFactory

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Build an internal BeanFactory for resolving target beans.
 * @param containingFactory the containing BeanFactory that originally defines the beans
 * @return an independent internal BeanFactory to hold copies of some target beans
 */
protected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory) {
	// Set parent so that references (up container hierarchies) are correctly resolved.
	DefaultListableBeanFactory internalBeanFactory = new DefaultListableBeanFactory(containingFactory);

	// Required so that all BeanPostProcessors, Scopes, etc become available.
	internalBeanFactory.copyConfigurationFrom(containingFactory);

	// Filter out BeanPostProcessors that are part of the AOP infrastructure,
	// since those are only meant to apply to beans defined in the original factory.
	for (Iterator<BeanPostProcessor> it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
		if (it.next() instanceof AopInfrastructureBean) {
			it.remove();
		}
	}

	return internalBeanFactory;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:AbstractBeanFactoryBasedTargetSourceCreator.java

示例12: findDefaultEntityManagerFactory

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的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: afterPropertiesSet

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    RequestMappingHandlerAdapter requestMappingHandlerAdapter = this.beanFactory.getBean(RequestMappingHandlerAdapter.class);
    List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
    List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
    if (beanFactory instanceof ConfigurableBeanFactory) {
        argumentResolvers.add(new WxArgumentResolver((ConfigurableBeanFactory) beanFactory));
    } else {
        argumentResolvers.add(new WxArgumentResolver(beanFactory.getBean(WxUserManager.class), beanFactory.getBean(WxUserProvider.class)));
    }
    returnValueHandlers.add(beanFactory.getBean(WxAsyncMessageReturnValueHandler.class));
    argumentResolvers.addAll(requestMappingHandlerAdapter.getArgumentResolvers());
    returnValueHandlers.addAll(requestMappingHandlerAdapter.getReturnValueHandlers());
    requestMappingHandlerAdapter.setArgumentResolvers(argumentResolvers);
    requestMappingHandlerAdapter.setReturnValueHandlers(returnValueHandlers);
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:17,代碼來源:WxBuildinMvcConfiguration.java

示例14: initArgumentResolvers

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
	ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ?
			(ConfigurableBeanFactory) this.beanFactory : null);

	// Annotation-based argument resolution
	resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, cbf));
	resolvers.add(new HeadersMethodArgumentResolver());

	// Type-based argument resolution
	resolvers.add(new MessageMethodArgumentResolver());

	if (this.customArgumentResolvers != null) {
		resolvers.addAll(this.customArgumentResolvers);
	}
	resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));

	return resolvers;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:DefaultMessageHandlerMethodFactory.java

示例15: invokeAwareMethods

import org.springframework.beans.factory.config.ConfigurableBeanFactory; //導入依賴的package包/類
/**
 * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
 * {@link BeanFactoryAware} contracts if implemented by the given {@code filter}.
 */
private void invokeAwareMethods(TypeFilter filter) {
	if (filter instanceof Aware) {
		if (filter instanceof EnvironmentAware) {
			((EnvironmentAware) filter).setEnvironment(this.environment);
		}
		if (filter instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) filter).setResourceLoader(this.resourceLoader);
		}
		if (filter instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
					this.resourceLoader.getClassLoader());
			((BeanClassLoaderAware) filter).setBeanClassLoader(classLoader);
		}
		if (filter instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
			((BeanFactoryAware) filter).setBeanFactory((BeanFactory) this.registry);
		}
	}
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:24,代碼來源:ComponentScanAnnotationParser.java


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