package com.skr.mdm.service.impl.reload;

import com.skr.mdm.annotation.MdmReloadHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author nfq
 * @date 2022/06/10 11:51
 */
@Slf4j
@Component
public class ReloadStrategyFactory implements BeanPostProcessor {


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean.getClass().isAnnotationPresent(MdmReloadHandler.class)) {
            ReloadHandlerChain.reloadHandlerList.add((ReloadHandler) bean);
        }
        return bean;
    }
}