当前位置: 首页>>代码示例>>Java>>正文


Java BeanPostProcessor类代码示例

本文整理汇总了Java中org.springframework.beans.factory.config.BeanPostProcessor的典型用法代码示例。如果您正苦于以下问题:Java BeanPostProcessor类的具体用法?Java BeanPostProcessor怎么用?Java BeanPostProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanPostProcessor类属于org.springframework.beans.factory.config包,在下文中一共展示了BeanPostProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postProcessBeanFactory

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
		throws BeansException, OsgiException {

	Bundle bundle = bundleContext.getBundle();
	try {
		// Try and load the annotation code using the bundle classloader
		Class<?> annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
		// instantiate the class
		final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);

		// everything went okay so configure the BPP and add it to the BF
		((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
		((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
		((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
		beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
	}
	catch (ClassNotFoundException exception) {
		log.info("Spring-DM annotation package could not be loaded from bundle ["
				+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
		if (log.isDebugEnabled())
			log.debug("Cannot load annotation injection processor", exception);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:24,代码来源:OsgiAnnotationPostProcessor.java

示例2: enforceExporterImporterDependency

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Takes care of enforcing the relationship between exporter and importers.
 * 
 * @param beanFactory
 */
private void enforceExporterImporterDependency(ConfigurableListableBeanFactory beanFactory) {
	Object instance = null;

	instance = AccessController.doPrivileged(new PrivilegedAction<Object>() {

		public Object run() {
			// create the service manager
			ClassLoader loader = AbstractOsgiBundleApplicationContext.class.getClassLoader();
			try {
				Class<?> managerClass = loader.loadClass(EXPORTER_IMPORTER_DEPENDENCY_MANAGER);
				return BeanUtils.instantiateClass(managerClass);
			} catch (ClassNotFoundException cnfe) {
				throw new ApplicationContextException("Cannot load class " + EXPORTER_IMPORTER_DEPENDENCY_MANAGER,
						cnfe);
			}
		}
	});

	// sanity check
	Assert.isInstanceOf(BeanFactoryAware.class, instance);
	Assert.isInstanceOf(BeanPostProcessor.class, instance);
	((BeanFactoryAware) instance).setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor((BeanPostProcessor) instance);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:30,代码来源:AbstractOsgiBundleApplicationContext.java

示例3: setBeanFactory

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的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

示例4: predictBeanType

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
@Override
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
	Class<?> targetType = mbd.getTargetType();
	if (targetType == null) {
		targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) :
				resolveBeanClass(mbd, beanName, typesToMatch));
		if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) {
			mbd.setTargetType(targetType);
		}
	}
	// Apply SmartInstantiationAwareBeanPostProcessors to predict the
	// eventual type after a before-instantiation shortcut.
	if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
				SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
				Class<?> predicted = ibp.predictBeanType(targetType, beanName);
				if (predicted != null && (typesToMatch.length != 1 || !FactoryBean.class.equals(typesToMatch[0]) ||
						FactoryBean.class.isAssignableFrom(predicted))) {
					return predicted;
				}
			}
		}
	}
	return targetType;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AbstractAutowireCapableBeanFactory.java

示例5: getEarlyBeanReference

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Obtain a reference for early access to the specified bean,
 * typically for the purpose of resolving a circular reference.
 * @param beanName the name of the bean (for error handling purposes)
 * @param mbd the merged bean definition for the bean
 * @param bean the raw bean instance
 * @return the object to expose as bean reference
 */
protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) {
	Object exposedObject = bean;
	if (bean != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
				SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
				exposedObject = ibp.getEarlyBeanReference(exposedObject, beanName);
				if (exposedObject == null) {
					return exposedObject;
				}
			}
		}
	}
	return exposedObject;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:AbstractAutowireCapableBeanFactory.java

示例6: applyMergedBeanDefinitionPostProcessors

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Apply MergedBeanDefinitionPostProcessors to the specified bean definition,
 * invoking their {@code postProcessMergedBeanDefinition} methods.
 * @param mbd the merged bean definition for the bean
 * @param beanType the actual type of the managed bean instance
 * @param beanName the name of the bean
 * @throws BeansException if any post-processing failed
 * @see MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition
 */
protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class<?> beanType, String beanName)
		throws BeansException {

	try {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof MergedBeanDefinitionPostProcessor) {
				MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) bp;
				bdp.postProcessMergedBeanDefinition(mbd, beanType, beanName);
			}
		}
	}
	catch (Exception ex) {
		throw new BeanCreationException(mbd.getResourceDescription(), beanName,
				"Post-processing failed of bean type [" + beanType + "] failed", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AbstractAutowireCapableBeanFactory.java

示例7: determineConstructorsFromBeanPostProcessors

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Determine candidate constructors to use for the given bean, checking all registered
 * {@link SmartInstantiationAwareBeanPostProcessor SmartInstantiationAwareBeanPostProcessors}.
 * @param beanClass the raw class of the bean
 * @param beanName the name of the bean
 * @return the candidate constructors, or {@code null} if none specified
 * @throws org.springframework.beans.BeansException in case of errors
 * @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors
 */
protected Constructor<?>[] determineConstructorsFromBeanPostProcessors(Class<?> beanClass, String beanName)
		throws BeansException {

	if (beanClass != null && hasInstantiationAwareBeanPostProcessors()) {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
				SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
				Constructor<?>[] ctors = ibp.determineCandidateConstructors(beanClass, beanName);
				if (ctors != null) {
					return ctors;
				}
			}
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AbstractAutowireCapableBeanFactory.java

示例8: buildInternalBeanFactory

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的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

示例9: setBeanFactory

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
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:ilivoo,项目名称:game,代码行数:27,代码来源:MyScriptFactoryPostProcessor.java

示例10: predictBeanType

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
@Override
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
	Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch);

	// Apply SmartInstantiationAwareBeanPostProcessors to predict the
	// eventual type after a before-instantiation shortcut.
	if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
				SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
				Class<?> predicted = ibp.predictBeanType(targetType, beanName);
				if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0] ||
						FactoryBean.class.isAssignableFrom(predicted))) {
					return predicted;
				}
			}
		}
	}
	return targetType;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AbstractAutowireCapableBeanFactory.java

示例11: filterPostProcessors

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Search for all DestructionAwareBeanPostProcessors in the List.
 * @param processors the List to search
 * @return the filtered List of DestructionAwareBeanPostProcessors
 */
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) {
	List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
	if (!CollectionUtils.isEmpty(processors)) {
		filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(processors.size());
		for (BeanPostProcessor processor : processors) {
			if (processor instanceof DestructionAwareBeanPostProcessor) {
				DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor;
				try {
					if (dabpp.requiresDestruction(bean)) {
						filteredPostProcessors.add(dabpp);
					}
				}
				catch (AbstractMethodError err) {
					// A pre-4.3 third-party DestructionAwareBeanPostProcessor...
					// As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true.
					filteredPostProcessors.add(dabpp);
				}
			}
		}
	}
	return filteredPostProcessors;
}
 
开发者ID:txazo,项目名称:spring,代码行数:28,代码来源:DisposableBeanAdapter.java

示例12: hasApplicableProcessors

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Check whether the given bean has destruction-aware post-processors applying to it.
 * @param bean the bean instance
 * @param postProcessors the post-processor candidates
 */
public static boolean hasApplicableProcessors(Object bean, List<BeanPostProcessor> postProcessors) {
	if (!CollectionUtils.isEmpty(postProcessors)) {
		for (BeanPostProcessor processor : postProcessors) {
			if (processor instanceof DestructionAwareBeanPostProcessor) {
				DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor;
				try {
					if (dabpp.requiresDestruction(bean)) {
						return true;
					}
				}
				catch (AbstractMethodError err) {
					// A pre-4.3 third-party DestructionAwareBeanPostProcessor...
					// As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true.
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:txazo,项目名称:spring,代码行数:26,代码来源:DisposableBeanAdapter.java

示例13: main

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
public static void main(String[] args)throws Exception
	{
		// �������·���µ�beans.xml�ļ�������Spring����
//		ApplicationContext ctx = new
//			ClassPathXmlApplicationContext("beans.xml");
//		Person p = (Person)ctx.getBean("chinese");

		// ���������·���µ�beans.xml�ļ�����Resource����
		Resource isr = new ClassPathResource("beans.xml");
		// ����Ĭ�ϵ�BeanFactory����
		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
		// ��Ĭ�ϵ�BeanFactory��������isr��Ӧ��XML�����ļ�
		new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(isr);
		// ��ȡ�����е�Bean������
		BeanPostProcessor bp = (BeanPostProcessor)beanFactory.getBean("bp");
		// ע��Bean������
		beanFactory.addBeanPostProcessor(bp);
		Person p = (Person)beanFactory.getBean("chinese");

		p.useAxe();
	}
 
开发者ID:wolfogre,项目名称:CodesOfLightweightJavaEE,代码行数:22,代码来源:BeanTest.java

示例14: setupProcessor

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
/**
 * Sets up the bean post processor and conversion service
 *
 * @param beans - The bean factory for the the dictionary beans
 */
public static void setupProcessor(DefaultListableBeanFactory beans) {
    try {
        // UIF post processor that sets component ids
        BeanPostProcessor idPostProcessor = ComponentBeanPostProcessor.class.newInstance();
        beans.addBeanPostProcessor(idPostProcessor);
        beans.setBeanExpressionResolver(new StandardBeanExpressionResolver() {
            @Override
            protected void customizeEvaluationContext(StandardEvaluationContext evalContext) {
                try {
                    evalContext.registerFunction("getService", ExpressionFunctions.class.getDeclaredMethod("getService", new Class[]{String.class}));
                } catch(NoSuchMethodException me) {
                    LOG.error("Unable to register custom expression to data dictionary bean factory", me);
                }
            }
        });

        // special converters for shorthand map and list property syntax
        GenericConversionService conversionService = new GenericConversionService();
        conversionService.addConverter(new StringMapConverter());
        conversionService.addConverter(new StringListConverter());

        beans.setConversionService(conversionService);
    } catch (Exception e1) {
        throw new DataDictionaryException("Cannot create component decorator post processor: " + e1.getMessage(),
                e1);
    }
}
 
开发者ID:kuali,项目名称:rice,代码行数:33,代码来源:DataDictionary.java

示例15: postProcessBeanFactory

import org.springframework.beans.factory.config.BeanPostProcessor; //导入依赖的package包/类
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
		throws BeansException, OsgiException {

	Bundle bundle = bundleContext.getBundle();
	try {
		// Try and load the annotation code using the bundle classloader
		Class annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
		// instantiate the class
		final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);

		// everything went okay so configure the BPP and add it to the BF
		((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
		((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
		((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
		beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
	}
	catch (ClassNotFoundException exception) {
		log.info("Spring-DM annotation package could not be loaded from bundle ["
				+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
		if (log.isDebugEnabled())
			log.debug("Cannot load annotation injection processor", exception);
	}
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:24,代码来源:OsgiAnnotationPostProcessor.java


注:本文中的org.springframework.beans.factory.config.BeanPostProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。