content: package com.open.capacity.config;
  
  import org.apache.commons.lang3.StringUtils;
  import org.springframework.beans.BeansException;
  import org.springframework.beans.factory.FactoryBean;
  import org.springframework.beans.factory.InitializingBean;
  import org.springframework.beans.factory.config.BeanPostProcessor;
  import org.springframework.stereotype.Component;
  
  /**
   * @Author: [gitgeek]
   * @Date: [2018-07-14 09:46]
   * @Description: [ ]
   * @Version: [1.0.0]
   * @Copy: [com.zzg]
   */
  @Component
  public class TokenStorePostProcessor implements BeanPostProcessor {
      /**
       * Apply this BeanPostProcessor to the given new bean instance <i>before</i> any bean
       * initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
       * or a custom init-method). The bean will already be populated with property values.
       * The returned bean instance may be a wrapper around the original.
       *
       * @param bean     the new bean instance
       * @param beanName the name of the bean
       * @return the bean instance to use, either the original or a wrapped one;
       * if {@code null}, no subsequent BeanPostProcessors will be invoked
       * @throws BeansException in case of errors
       * @see InitializingBean#afterPropertiesSet
       */
      @Override
      public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
          return bean;
      }
  
      /**
       * Apply this BeanPostProcessor to the given new bean instance <i>after</i> any bean
       * initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
       * or a custom init-method). The bean will already be populated with property values.
       * The returned bean instance may be a wrapper around the original.
       * <p>In case of a FactoryBean, this callback will be invoked for both the FactoryBean
       * instance and the objects created by the FactoryBean (as of Spring 2.0). The
       * post-processor can decide whether to apply to either the FactoryBean or created
       * objects or both through corresponding {@code bean instanceof FactoryBean} checks.
       * <p>This callback will also be invoked after a short-circuiting triggered by a
       * {@link InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation} method,
       * in contrast to all other BeanPostProcessor callbacks.
       *
       * @param bean     the new bean instance
       * @param beanName the name of the bean
       * @return the bean instance to use, either the original or a wrapped one;
       * if {@code null}, no subsequent BeanPostProcessors will be invoked
       * @throws BeansException in case of errors
       * @see InitializingBean#afterPropertiesSet
       * @see FactoryBean
       */
      @Override
      public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  //        System.out.println(beanName);
          if (StringUtils.equals(beanName,"inMemoryTokenStore")){
              return this;
          }
          return bean;
      }
  }
  