Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.BeanPostProcessor


    root.setServletContext(sc);
    root.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/applicationContext.xml"});
    root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
      @Override
      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
          @Override
          @SuppressWarnings("unchecked")
          public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
            if (bean instanceof TestBean) {
              ((TestBean) bean).getFriends().add("myFriend");
View Full Code Here


    List<BeanPostProcessor> internalPostProcessors = new ArrayList<BeanPostProcessor>();
    List<String> orderedPostProcessorNames = new ArrayList<String>();
    List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
    for (String ppName : postProcessorNames) {
      if (isTypeMatch(ppName, PriorityOrdered.class)) {
        BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
        priorityOrderedPostProcessors.add(pp);
        if (pp instanceof MergedBeanDefinitionPostProcessor) {
          internalPostProcessors.add(pp);
        }
      }
      else if (isTypeMatch(ppName, Ordered.class)) {
        orderedPostProcessorNames.add(ppName);
      }
      else {
        nonOrderedPostProcessorNames.add(ppName);
      }
    }

    // First, register the BeanPostProcessors that implement PriorityOrdered.
    OrderComparator.sort(priorityOrderedPostProcessors);
    registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

    // Next, register the BeanPostProcessors that implement Ordered.
    List<BeanPostProcessor> orderedPostProcessors = new ArrayList<BeanPostProcessor>();
    for (String ppName : orderedPostProcessorNames) {
      BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
      orderedPostProcessors.add(pp);
      if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
      }
    }
    OrderComparator.sort(orderedPostProcessors);
    registerBeanPostProcessors(beanFactory, orderedPostProcessors);

    // Now, register all regular BeanPostProcessors.
    List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
    for (String ppName : nonOrderedPostProcessorNames) {
      BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
      nonOrderedPostProcessors.add(pp);
      if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
      }
    }
View Full Code Here

    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 it = this.scriptBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
      BeanPostProcessor postProcessor = (BeanPostProcessor) it.next();
      if (postProcessor instanceof AopInfrastructureBean) {
        it.remove();
      }
    }
  }
View Full Code Here

  public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
      throws BeansException {

    Object result = existingBean;
    for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext();) {
      BeanPostProcessor beanProcessor = (BeanPostProcessor) it.next();
      result = beanProcessor.postProcessBeforeInitialization(result, beanName);
    }
    return result;
  }
View Full Code Here

  public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
      throws BeansException {

    Object result = existingBean;
    for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext();) {
      BeanPostProcessor beanProcessor = (BeanPostProcessor) it.next();
      result = beanProcessor.postProcessAfterInitialization(result, beanName);
    }
    return result;
  }
View Full Code Here

    }
    // Apply SmartInstantiationAwareBeanPostProcessors to predict the
    // eventual type after a before-instantiation shortcut.
    if (beanClass != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
      for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext(); ) {
        BeanPostProcessor bp = (BeanPostProcessor) it.next();
        if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
          SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
          Class processedType = ibp.predictBeanType(beanClass, beanName);
          if (processedType != null) {
            return processedType;
View Full Code Here

   */
  protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) {
    Object exposedObject = bean;
    if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
      for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext(); ) {
        BeanPostProcessor bp = (BeanPostProcessor) it.next();
        if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
          SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
          exposedObject = ibp.getEarlyBeanReference(exposedObject, beanName);
        }
      }
View Full Code Here

   */
  protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class beanType, String beanName)
      throws BeansException {

    for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext();) {
      BeanPostProcessor beanProcessor = (BeanPostProcessor) it.next();
      if (beanProcessor instanceof MergedBeanDefinitionPostProcessor) {
        MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) beanProcessor;
        bdp.postProcessMergedBeanDefinition(mbd, beanType, beanName);
      }
    }
View Full Code Here

   */
  protected Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass, String beanName)
      throws BeansException {

    for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext();) {
      BeanPostProcessor beanProcessor = (BeanPostProcessor) it.next();
      if (beanProcessor instanceof InstantiationAwareBeanPostProcessor) {
        InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) beanProcessor;
        Object result = ibp.postProcessBeforeInstantiation(beanClass, beanName);
        if (result != null) {
          return result;
View Full Code Here

  protected Constructor[] determineConstructorsFromBeanPostProcessors(Class beanClass, String beanName)
      throws BeansException {

    if (hasInstantiationAwareBeanPostProcessors()) {
      for (Iterator it = getBeanPostProcessors().iterator(); it.hasNext();) {
        BeanPostProcessor beanProcessor = (BeanPostProcessor) it.next();
        if (beanProcessor instanceof SmartInstantiationAwareBeanPostProcessor) {
          SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) beanProcessor;
          Constructor[] ctors = ibp.determineCandidateConstructors(beanClass, beanName);
          if (ctors != null) {
            return ctors;
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.BeanPostProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.