All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.ishow.starter.rpc.processor.ClientBeanPostProcessor Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package cn.ishow.starter.rpc.processor;

import cn.ishow.starter.rpc.basic.CustomClient;
import cn.ishow.starter.rpc.context.RpcContext;
import feign.Client;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author chongyin
 * @create 2022/9/20 下午7:31
 * @description 功能描述
 */
public class ClientBeanPostProcessor implements BeanPostProcessor {
    /**
     * 是否完成代理
     */
    private final AtomicBoolean complete = new AtomicBoolean(false);
    @Autowired
    private RpcContext rpcContext;

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Client
                && !(bean instanceof CustomClient)
                && complete.compareAndSet(false, true)) {
            return new CustomClient((Client) bean, rpcContext);
        }
        return bean;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy