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);
}
}
java类org.springframework.beans.factory.config.BeanPostProcessor的实例源码
OsgiAnnotationPostProcessor.java 文件源码
项目:spring-osgi
阅读 23
收藏 0
点赞 0
评论 0
AbstractOsgiBundleApplicationContext.java 文件源码
项目:spring-osgi
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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() {
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);
}
DataDictionary.java 文件源码
项目:kuali_rice
阅读 32
收藏 0
点赞 0
评论 0
/**
* Sets up the bean post processor and conversion service
*
* @param beans - The bean factory for the the dictionary beans
*/
public static void setupProcessor(KualiDefaultListableBeanFactory beans) {
try {
// UIF post processor that sets component ids
BeanPostProcessor idPostProcessor = ComponentBeanPostProcessor.class.newInstance();
beans.addBeanPostProcessor(idPostProcessor);
beans.setBeanExpressionResolver(new StandardBeanExpressionResolver());
// 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);
}
}
CasWebApplicationContext.java 文件源码
项目:cas-5.1.0
阅读 21
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* Reset the value resolver on the inner {@link ScheduledAnnotationBeanPostProcessor}
* so that we can parse durations. This is due to how {@link org.springframework.scheduling.annotation.SchedulingConfiguration}
* creates the processor and does not provide a way for one to inject a value resolver.
*/
@Override
protected void onRefresh() {
final ScheduledAnnotationBeanPostProcessor sch = (ScheduledAnnotationBeanPostProcessor)
getBeanFactory().getBean(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME, BeanPostProcessor.class);
sch.setEmbeddedValueResolver(new CasConfigurationEmbeddedValueResolver(this));
super.onRefresh();
}
ServiceReferenceInjectionBeanPostProcessor.java 文件源码
项目:gemini.blueprint
阅读 26
收藏 0
点赞 0
评论 0
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
String beanName) throws BeansException {
MutablePropertyValues newprops = new MutablePropertyValues(pvs);
for (PropertyDescriptor pd : pds) {
ServiceReference s = hasServiceProperty(pd);
if (s != null && !pvs.contains(pd.getName())) {
try {
if (logger.isDebugEnabled())
logger.debug("Processing annotation [" + s + "] for [" + beanName + "." + pd.getName() + "]");
FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
// BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that
// the call to getObject() will not fail with ServiceUnavailable. This is safe to do because
// ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are
// satisfied before stageTwo() is run.
if (bean instanceof BeanPostProcessor) {
ImporterCallAdapter.setCardinality(importer, Availability.OPTIONAL);
}
newprops.addPropertyValue(pd.getName(), importer.getObject());
}
catch (Exception e) {
throw new FatalBeanException("Could not create service reference", e);
}
}
}
return newprops;
}
AbstractDelegatedExecutionApplicationContext.java 文件源码
项目:gemini.blueprint
阅读 27
收藏 0
点赞 0
评论 0
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (!(bean instanceof BeanPostProcessor)
&& this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {
if (logger.isInfoEnabled()) {
logger.info("Bean '" + beanName + "' is not eligible for getting processed by all "
+ "BeanPostProcessors (for example: not eligible for auto-proxying)");
}
}
return bean;
}
AbstractDelegatedExecutionApplicationContext.java 文件源码
项目:gemini.blueprint
阅读 29
收藏 0
点赞 0
评论 0
/**
* Register the given BeanPostProcessor beans.
*/
private void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory,
List<BeanPostProcessor> postProcessors) {
for (BeanPostProcessor postProcessor : postProcessors) {
beanFactory.addBeanPostProcessor(postProcessor);
}
}
PostProcessorRegistrationDelegate.java 文件源码
项目:lams
阅读 29
收藏 0
点赞 0
评论 0
/**
* Register the given BeanPostProcessor beans.
*/
private static void registerBeanPostProcessors(
ConfigurableListableBeanFactory beanFactory, List<BeanPostProcessor> postProcessors) {
for (BeanPostProcessor postProcessor : postProcessors) {
beanFactory.addBeanPostProcessor(postProcessor);
}
}
PostProcessorRegistrationDelegate.java 文件源码
项目:lams
阅读 27
收藏 0
点赞 0
评论 0
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean != null && !(bean instanceof BeanPostProcessor) &&
this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {
if (logger.isInfoEnabled()) {
logger.info("Bean '" + beanName + "' of type [" + bean.getClass() +
"] is not eligible for getting processed by all BeanPostProcessors " +
"(for example: not eligible for auto-proxying)");
}
}
return bean;
}
DisposableBeanAdapter.java 文件源码
项目:lams
阅读 22
收藏 0
点赞 0
评论 0
/**
* Create a new DisposableBeanAdapter for the given bean.
* @param bean the bean instance (never {@code null})
* @param beanName the name of the bean
* @param beanDefinition the merged bean definition
* @param postProcessors the List of BeanPostProcessors
* (potentially DestructionAwareBeanPostProcessor), if any
*/
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
List<BeanPostProcessor> postProcessors, AccessControlContext acc) {
Assert.notNull(bean, "Disposable bean must not be null");
this.bean = bean;
this.beanName = beanName;
this.invokeDisposableBean =
(this.bean instanceof DisposableBean && !beanDefinition.isExternallyManagedDestroyMethod("destroy"));
this.nonPublicAccessAllowed = beanDefinition.isNonPublicAccessAllowed();
this.acc = acc;
String destroyMethodName = inferDestroyMethodIfNecessary(bean, beanDefinition);
if (destroyMethodName != null && !(this.invokeDisposableBean && "destroy".equals(destroyMethodName)) &&
!beanDefinition.isExternallyManagedDestroyMethod(destroyMethodName)) {
this.destroyMethodName = destroyMethodName;
this.destroyMethod = determineDestroyMethod();
if (this.destroyMethod == null) {
if (beanDefinition.isEnforceDestroyMethod()) {
throw new BeanDefinitionValidationException("Couldn't find a destroy method named '" +
destroyMethodName + "' on bean with name '" + beanName + "'");
}
}
else {
Class<?>[] paramTypes = this.destroyMethod.getParameterTypes();
if (paramTypes.length > 1) {
throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" +
beanName + "' has more than one parameter - not supported as destroy method");
}
else if (paramTypes.length == 1 && !paramTypes[0].equals(boolean.class)) {
throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" +
beanName + "' has a non-boolean parameter - not supported as destroy method");
}
}
}
this.beanPostProcessors = filterPostProcessors(postProcessors);
}