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

com.seven.cow.beans.spring.boot.starter.util.OuterServiceUtils Maven / Gradle / Ivy

There is a newer version: 0.2.4
Show newest version
package com.seven.cow.beans.spring.boot.starter.util;


import com.seven.cow.beans.spring.boot.starter.proxy.ProxyFactory;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public abstract class OuterServiceUtils {

    private static final Map, ProxyFactory> proxyFactoryHashMap = new HashMap<>();

    public static void putOuterServiceProxy(ProxyFactory proxyFactory) {
        proxyFactoryHashMap.put(proxyFactory.getTarget(), proxyFactory);
    }

    public static void setOuterServiceProxyBean(Class beanClass, Object beanInstance) {
        ProxyFactory proxyFactory = proxyFactoryHashMap.get(beanClass);
        if (null == proxyFactory) {
            return;
        }
        Field field = ReflectionUtils.findField(ProxyFactory.class, "object");
        if (null != field) {
            ReflectionUtils.makeAccessible(field);
            ReflectionUtils.setField(field, proxyFactory, beanInstance);
        }
        proxyFactoryHashMap.remove(beanClass);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy