RpcServiceFactoryBean.java 1.2 KB
Newer Older
L
lvxuhong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
package github.javaguide.spring.rpcservice;

import github.javaguide.ClientProxy;
import org.springframework.beans.factory.FactoryBean;

/**
 * @description:
 * @author:lvxuhong
 * @date:2020/6/18
 */
public class RpcServiceFactoryBean<T> implements FactoryBean<T> {

    private Class<T> rpcServiceInterface;

    public RpcServiceFactoryBean() {

    }

    public RpcServiceFactoryBean(Class<T> rpcServiceInterface) {
        this.rpcServiceInterface = rpcServiceInterface;
    }

    @Override
    public T getObject() throws Exception {
        if (rpcServiceInterface == null) {
            throw new IllegalStateException("");
        }

        return ClientProxy.getServiceProxy(rpcServiceInterface);
//        return (T) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[]{rpcServiceInterface}, new InvocationHandler() {
//            @Override
//            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
//                if(method.equals()){}
//                return null;
//            }
//        });
    }

    @Override
    public Class<?> getObjectType() {
        return rpcServiceInterface;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }


}