@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " + "non-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. this.scriptBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> beanPostProcessor instanceof AopInfrastructureBean); }
/** * 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. internalBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> beanPostProcessor instanceof AopInfrastructureBean); return internalBeanFactory; }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " + "non-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. this.scriptBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> beanPostProcessor instanceof AopInfrastructureBean); }
for (BeanPostProcessor processor : getBeanPostProcessors()) { if (processor instanceof MergedBeanDefinitionPostProcessor) { ((MergedBeanDefinitionPostProcessor) processor).resetBeanDefinition(beanName);
for (BeanPostProcessor bpp : beanFactory.getBeanPostProcessors()) { if (bpp instanceof AutowiredAnnotationBeanPostProcessor) { resetAutowiredAnnotationBeanPostProcessorCache((AutowiredAnnotationBeanPostProcessor)bpp);
for (BeanPostProcessor processor : getBeanPostProcessors()) { if (processor instanceof MergedBeanDefinitionPostProcessor) { ((MergedBeanDefinitionPostProcessor) processor).resetBeanDefinition(beanName);
public static final void setBlocking(ApplicationContext ctx, EndpointImpl impl) { AutowireCapableBeanFactory fact = ctx.getAutowireCapableBeanFactory(); if (fact instanceof DefaultListableBeanFactory) { DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory)fact; for (BeanPostProcessor bpp : dlbf.getBeanPostProcessors()) { if (CommonAnnotationBeanPostProcessor.class.isInstance(bpp)) { impl.getServerFactory().setBlockPostConstruct(true); impl.getServerFactory().setBlockInjection(false); return; } if (bpp instanceof Jsr250BeanPostProcessor) { impl.getServerFactory().setBlockInjection(true); } } } }
/** * Ensure that all externally visible {@link BeanPostProcessor BeanPostProcessors} are applied * to hidden beans. BPP instances from the parent (external) bean factory are merged with those * from this (internal) bean factory, taking care to avoid duplication. In duplication cases, * the parent BPP takes precedence. */ @Override @SuppressWarnings("unchecked") public List getBeanPostProcessors() { LinkedHashSet mergedBeanPostProcessors = new LinkedHashSet(); mergedBeanPostProcessors.addAll(getParentBeanFactory().getBeanPostProcessors()); mergedBeanPostProcessors.addAll(super.getBeanPostProcessors()); return new ArrayList(mergedBeanPostProcessors); }
/** * TODO: JAVADOC * * @see #parentHasInstantiationAwareBeanPostProcessors() * @see AbstractBeanFactory#addBeanPostProcessor(BeanPostProcessor) */ private boolean parentHasDestructionAwareBeanPostProcessors() { for (Object bpp : getParentBeanFactory().getBeanPostProcessors()) if (bpp instanceof DestructionAwareBeanPostProcessor) return true; return false; }
/** * Duplicates logic in {@link AbstractBeanFactory#addBeanPostProcessor(BeanPostProcessor)}. * Ideally would call {@link AbstractBeanFactory#hasInstantiationAwareBeanPostProcessors()}, * however this method is protected. * * @see AbstractBeanFactory#addBeanPostProcessor(BeanPostProcessor) */ private boolean parentHasInstantiationAwareBeanPostProcessors() { for (Object bpp : getParentBeanFactory().getBeanPostProcessors()) if (bpp instanceof InstantiationAwareBeanPostProcessor) return true; return false; }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " + "non-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. this.scriptBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> beanPostProcessor instanceof AopInfrastructureBean); }
/** * Extension point for special subclasses that want to do more complex * things with the bean factory prior to refresh. The default implementation * copies all configuration from the parent according to the * {@link #setCopyConfiguration(boolean) flag} set. * * @param parent the parent bean factory for the new context (will never be * null) * @param beanFactory the new bean factory before bean definitions are * loaded * * @see ClassPathXmlApplicationContextFactory#setCopyConfiguration(boolean) * @see DefaultListableBeanFactory#copyConfigurationFrom(ConfigurableBeanFactory) */ protected void prepareBeanFactory(DefaultListableBeanFactory parent, DefaultListableBeanFactory beanFactory) { if (copyConfiguration && parent != null) { beanFactory.copyConfigurationFrom(parent); @SuppressWarnings("unchecked") List<BeanPostProcessor> beanPostProcessors = beanFactory.getBeanPostProcessors(); for (BeanPostProcessor beanPostProcessor : new ArrayList<BeanPostProcessor>(beanPostProcessors)) { for (Class<?> cls : beanPostProcessorExcludeClasses) { if (cls.isAssignableFrom(beanPostProcessor.getClass())) { logger.debug("Removing bean post processor: " + beanPostProcessor + " of type " + cls); beanPostProcessors.remove(beanPostProcessor); } } } } }
@Override public void destroy() throws Exception { @SuppressWarnings("unchecked") List<BeanPostProcessor> beanPostProcessors = context.getDefaultListableBeanFactory().getBeanPostProcessors(); for (BeanPostProcessor p : beanPostProcessors) { if (p instanceof DestructionAwareBeanPostProcessor) ((DestructionAwareBeanPostProcessor)p).postProcessBeforeDestruction(bean, beanName); } }
/** * 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(); // effectively deprecated: use List.removeIf on Java 8+ } } return internalBeanFactory; }
@Override public void destroy() throws Exception { List<BeanPostProcessor> beanPostProcessors = context.getDefaultListableBeanFactory().getBeanPostProcessors(); for (BeanPostProcessor p : beanPostProcessors) { if (p instanceof DestructionAwareBeanPostProcessor) ((DestructionAwareBeanPostProcessor)p).postProcessBeforeDestruction(bean, beanName); } }
@Override public void destroy() throws Exception { List<BeanPostProcessor> beanPostProcessors = context.getDefaultListableBeanFactory().getBeanPostProcessors(); for (BeanPostProcessor p : beanPostProcessors) { if (p instanceof DestructionAwareBeanPostProcessor) ((DestructionAwareBeanPostProcessor)p).postProcessBeforeDestruction(bean, beanName); } }
/** * 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. internalBeanFactory.getBeanPostProcessors().removeIf(beanPostProcessor -> beanPostProcessor instanceof AopInfrastructureBean); return internalBeanFactory; }
public static final void setBlocking(ApplicationContext ctx, EndpointImpl impl) { AutowireCapableBeanFactory fact = ctx.getAutowireCapableBeanFactory(); if (fact instanceof DefaultListableBeanFactory) { DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory)fact; for (BeanPostProcessor bpp : dlbf.getBeanPostProcessors()) { if (CommonAnnotationBeanPostProcessor.class.isInstance(bpp)) { impl.getServerFactory().setBlockPostConstruct(true); impl.getServerFactory().setBlockInjection(false); return; } if (bpp instanceof Jsr250BeanPostProcessor) { impl.getServerFactory().setBlockInjection(true); } } } }